class Plugin

Defines a Plugin annotation object.

Annotations in plugin classes can utilize 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

Expanded class hierarchy of Plugin

161 files declare their use of Plugin
Action.php in drupal/core/lib/Drupal/Core/Annotation/Action.php
Contains \Drupal\Core\Annotation\Action.
ActiveTopicsBlock.php in drupal/core/modules/forum/lib/Drupal/forum/Plugin/Block/ActiveTopicsBlock.php
Contains \Drupal\forum\Plugin\Block\ActiveTopicsBlock.
AggregatorCategoryBlock.php in drupal/core/modules/aggregator/lib/Drupal/aggregator/Plugin/Block/AggregatorCategoryBlock.php
Contains \Drupal\aggregator\Plugin\Block\AggregatorCategoryBlock.
AggregatorFeedBlock.php in drupal/core/modules/aggregator/lib/Drupal/aggregator/Plugin/Block/AggregatorFeedBlock.php
Contains \Drupal\aggregator\Plugin\Block\AggregatorFeedBlock.
AggregatorFetcher.php in drupal/core/modules/aggregator/lib/Drupal/aggregator/Annotation/AggregatorFetcher.php
Contains \Drupal\aggregator\Annotation\AggregatorFetcher.

... See full list

2 string references to 'Plugin'
block.schema.yml in drupal/core/modules/block/config/schema/block.schema.yml
drupal/core/modules/block/config/schema/block.schema.yml
tour.schema.yml in drupal/core/modules/tour/config/schema/tour.schema.yml
drupal/core/modules/tour/config/schema/tour.schema.yml
146 classes are annotated with Plugin
ActiveTopicsBlock in drupal/core/modules/forum/lib/Drupal/forum/Plugin/Block/ActiveTopicsBlock.php
Provides an 'Active forum topics' block.
AggregatorCategoryBlock in drupal/core/modules/aggregator/lib/Drupal/aggregator/Plugin/Block/AggregatorCategoryBlock.php
Provides an 'Aggregator category' block for the latest items in a category.
AggregatorFeedBlock in drupal/core/modules/aggregator/lib/Drupal/aggregator/Plugin/Block/AggregatorFeedBlock.php
Provides an 'Aggregator feed' block with the latest items from the feed.
Apple in drupal/core/modules/system/tests/modules/plugin_test/lib/Drupal/plugin_test/Plugin/plugin_test/fruit/Apple.php
Plugin annotation @Plugin( id = "apple", label = "Apple", color = "green" )
ArgumentDefaultTest in drupal/core/modules/views/tests/views_test_data/lib/Drupal/views_test_data/Plugin/views/argument_default/ArgumentDefaultTest.php
Defines a argument default test plugin.

... See full list

File

drupal/core/lib/Drupal/Component/Annotation/Plugin.php, line 23
Contains Drupal\Component\Annotation\Plugin.

Namespace

Drupal\Component\Annotation
View source
class Plugin implements AnnotationInterface {

  /**
   * The plugin definiton 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::mergeDeep($defaults, $parsed_values);
  }

  /**
   * 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 = array();
    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;
  }

  /**
   * Implements Drupal\Core\Annotation\AnnotationInterface::get().
   */
  public function get() {
    return $this->definition;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Plugin::$definition protected property The plugin definiton read from the class annotation.
Plugin::get public function Implements Drupal\Core\Annotation\AnnotationInterface::get(). Overrides AnnotationInterface::get
Plugin::parse protected function Parses an annotation into its definition.
Plugin::__construct public function Constructs a Plugin object.