class Plugin in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/lib/Drupal/Component/Annotation/Plugin.php \Drupal\Component\Annotation\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 AnnotationInterface
Expanded class hierarchy of Plugin
Related topics
33 files declare their use of Plugin
- Action.php in core/
lib/ Drupal/ Core/ Annotation/ Action.php - Contains \Drupal\Core\Annotation\Action.
- AggregatorFetcher.php in core/
modules/ aggregator/ src/ Annotation/ AggregatorFetcher.php - Contains \Drupal\aggregator\Annotation\AggregatorFetcher.
- AggregatorParser.php in core/
modules/ aggregator/ src/ Annotation/ AggregatorParser.php - Contains \Drupal\aggregator\Annotation\AggregatorParser.
- AggregatorProcessor.php in core/
modules/ aggregator/ src/ Annotation/ AggregatorProcessor.php - Contains \Drupal\aggregator\Annotation\AggregatorProcessor.
- Archiver.php in core/
lib/ Drupal/ Core/ Archiver/ Annotation/ Archiver.php - Contains \Drupal\Core\Archiver\Annotation\Archiver.
8 string references to 'Plugin'
- admin_toolbar_tools.routing.yml in modules/
admin_toolbar/ admin_toolbar_tools/ admin_toolbar_tools.routing.yml - modules/admin_toolbar/admin_toolbar_tools/admin_toolbar_tools.routing.yml
- block.schema.yml in core/
modules/ block/ config/ schema/ block.schema.yml - core/modules/block/config/schema/block.schema.yml
- ContextualLinkManagerTest::testPluginDefinitionAlter in core/
tests/ Drupal/ Tests/ Core/ Menu/ ContextualLinkManagerTest.php - Tests the plugins alter hook.
- migrate.data_types.schema.yml in core/
modules/ migrate/ config/ schema/ migrate.data_types.schema.yml - core/modules/migrate/config/schema/migrate.data_types.schema.yml
- migrate_drupal.source.schema.yml in core/
modules/ migrate_drupal/ config/ schema/ migrate_drupal.source.schema.yml - core/modules/migrate_drupal/config/schema/migrate_drupal.source.schema.yml
7 classes are annotated with Plugin
- Apple in core/
modules/ system/ tests/ modules/ plugin_test/ src/ Plugin/ plugin_test/ fruit/ Apple.php - Plugin annotation @Plugin( id = "apple", label = "Apple", color = "green" )
- Banana in core/
modules/ system/ tests/ modules/ plugin_test/ src/ Plugin/ plugin_test/ fruit/ Banana.php - Plugin annotation @Plugin( id = "banana", label = "Banana", color = "yellow", uses = { "bread" = @Translation("Banana bread") } )
- Cherry in core/
modules/ system/ tests/ modules/ plugin_test/ src/ Plugin/ plugin_test/ fruit/ Cherry.php - Plugin annotation @Plugin( id = "cherry", label = "Cherry", color = "red" )
- CustomDirectoryExample1 in core/
modules/ system/ tests/ modules/ plugin_test/ src/ CustomDirectoryExample1.php - Provides a test plugin within a custom directory.
- CustomDirectoryExample2 in core/
modules/ system/ tests/ modules/ plugin_test/ src/ CustomDirectoryExample2.php - Provides a test plugin within a custom directory.
File
- core/
lib/ Drupal/ Component/ Annotation/ Plugin.php, line 25 - Contains \Drupal\Component\Annotation\Plugin.
Namespace
Drupal\Component\AnnotationView 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::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;
}
/**
* {@inheritdoc}
*/
public function get() {
return $this->definition;
}
/**
* {@inheritdoc}
*/
public function getProvider() {
return isset($this->definition['provider']) ? $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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
Plugin:: |
protected | property | The plugin definition read from the class annotation. | 1 |
Plugin:: |
public | function |
Gets the value of an annotation. Overrides AnnotationInterface:: |
2 |
Plugin:: |
public | function |
Gets the class of the annotated class. Overrides AnnotationInterface:: |
|
Plugin:: |
public | function |
Gets the unique ID for this annotated class. Overrides AnnotationInterface:: |
|
Plugin:: |
public | function |
Gets the name of the provider of the annotated class. Overrides AnnotationInterface:: |
|
Plugin:: |
protected | function | Parses an annotation into its definition. | |
Plugin:: |
public | function |
Sets the class of the annotated class. Overrides AnnotationInterface:: |
|
Plugin:: |
public | function |
Sets the name of the provider of the annotated class. Overrides AnnotationInterface:: |
|
Plugin:: |
public | function | Constructs a Plugin object. | 1 |