Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Plugin.php

class Plugin

Same name in this branch
  1. 11.1.x vendor/dealerdirect/phpcodesniffer-composer-installer/src/Plugin.php \PHPCSStandards\Composer\Plugin\Installers\PHPCodeSniffer\Plugin
  2. 11.1.x vendor/phpstan/extension-installer/src/Plugin.php \PHPStan\ExtensionInstaller\Plugin
  3. 11.1.x vendor/php-http/discovery/src/Composer/Plugin.php \Http\Discovery\Composer\Plugin
  4. 11.1.x vendor/composer/installers/src/Composer/Installers/Plugin.php \Composer\Installers\Plugin
  5. 11.1.x vendor/tbachert/spi/src/Composer/Plugin.php \Nevay\SPI\Composer\Plugin
  6. 11.1.x composer/Plugin/Scaffold/Plugin.php \Drupal\Composer\Plugin\Scaffold\Plugin
  7. 11.1.x core/lib/Drupal/Component/Plugin/Attribute/Plugin.php \Drupal\Component\Plugin\Attribute\Plugin

Defines a Plugin annotation object.

Annotations in plugin classes can use this class in order to pass various metadata about the plugin through the parser to DiscoveryInterface::getDefinitions() calls. This allows the metadata of a class to be located with the class itself, rather than in module-based info hooks.

Hierarchy

  • class \Drupal\Component\Annotation\Plugin implements \Drupal\Component\Annotation\AnnotationInterface

Expanded class hierarchy of Plugin

Related topics

Plugin API
Using the Plugin API
Annotations
Annotations for class discovery and metadata description.
35 files declare their use of Plugin
Action.php in core/lib/Drupal/Core/Annotation/Action.php
Archiver.php in core/lib/Drupal/Core/Archiver/Annotation/Archiver.php
Block.php in core/lib/Drupal/Core/Block/Annotation/Block.php
CKEditor5AspectsOfCKEditor5Plugin.php in core/modules/ckeditor5/src/Annotation/CKEditor5AspectsOfCKEditor5Plugin.php
CKEditor5Plugin.php in core/modules/ckeditor5/src/Annotation/CKEditor5Plugin.php

... See full list

14 string references to 'Plugin'
Action::create in core/modules/system/src/Entity/Action.php
Constructs a new entity object, without permanently saving it.
block.schema.yml in core/modules/block/config/schema/block.schema.yml
core/modules/block/config/schema/block.schema.yml
DisplayPluginBase::calculateCacheMetadata in core/modules/views/src/Plugin/views/display/DisplayPluginBase.php
Calculates the display's cache metadata by inspecting each handler/plugin.
DisplayPluginBase::getAllPlugins in core/modules/views/src/Plugin/views/display/DisplayPluginBase.php
Gets all the plugins used by the display.
EntityBlock::getEntityId in core/modules/block/src/Plugin/migrate/destination/EntityBlock.php
Gets the entity ID of the row.

... See full list

File

core/lib/Drupal/Component/Annotation/Plugin.php, line 20

Namespace

Drupal\Component\Annotation
View source
class Plugin implements AnnotationInterface {
    
    /**
     * The plugin definition read from the class annotation.
     *
     * @var array
     */
    protected $definition;
    
    /**
     * Constructs a Plugin object.
     *
     * Builds up the plugin definition and invokes the get() method for any
     * classed annotations that were used.
     */
    public function __construct($values) {
        $reflection = new \ReflectionClass($this);
        // Only keep actual default values by ignoring NULL values.
        $defaults = array_filter($reflection->getDefaultProperties(), function ($value) {
            return $value !== NULL;
        });
        $parsed_values = $this->parse($values);
        $this->definition = NestedArray::mergeDeepArray([
            $defaults,
            $parsed_values,
        ], TRUE);
    }
    
    /**
     * Parses an annotation into its definition.
     *
     * @param array $values
     *   The annotation array.
     *
     * @return array
     *   The parsed annotation as a definition.
     */
    protected function parse(array $values) {
        $definitions = [];
        foreach ($values as $key => $value) {
            if ($value instanceof AnnotationInterface) {
                $definitions[$key] = $value->get();
            }
            elseif (is_array($value)) {
                $definitions[$key] = $this->parse($value);
            }
            else {
                $definitions[$key] = $value;
            }
        }
        return $definitions;
    }
    
    /**
     * {@inheritdoc}
     */
    public function get() {
        return $this->definition;
    }
    
    /**
     * {@inheritdoc}
     */
    public function getProvider() {
        return $this->definition['provider'] ?? FALSE;
    }
    
    /**
     * {@inheritdoc}
     */
    public function setProvider($provider) {
        $this->definition['provider'] = $provider;
    }
    
    /**
     * {@inheritdoc}
     */
    public function getId() {
        return $this->definition['id'];
    }
    
    /**
     * {@inheritdoc}
     */
    public function getClass() {
        return $this->definition['class'];
    }
    
    /**
     * {@inheritdoc}
     */
    public function setClass($class) {
        $this->definition['class'] = $class;
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title Overrides
Plugin::$definition protected property The plugin definition read from the class annotation. 1
Plugin::get public function Gets the value of an annotation. Overrides AnnotationInterface::get 5
Plugin::getClass public function Gets the class of the annotated class. Overrides AnnotationInterface::getClass 1
Plugin::getId public function Gets the unique ID for this annotated class. Overrides AnnotationInterface::getId
Plugin::getProvider public function Gets the name of the provider of the annotated class. Overrides AnnotationInterface::getProvider 1
Plugin::parse protected function Parses an annotation into its definition.
Plugin::setClass public function Sets the class of the annotated class. Overrides AnnotationInterface::setClass 1
Plugin::setProvider public function Sets the name of the provider of the annotated class. Overrides AnnotationInterface::setProvider
Plugin::__construct public function Constructs a Plugin object. 3
RSS feed
Powered by Drupal