class AnnotationBridgeDecorator

Same name in other branches
  1. 8.9.x core/lib/Drupal/Component/Annotation/Plugin/Discovery/AnnotationBridgeDecorator.php \Drupal\Component\Annotation\Plugin\Discovery\AnnotationBridgeDecorator
  2. 10 core/lib/Drupal/Component/Annotation/Plugin/Discovery/AnnotationBridgeDecorator.php \Drupal\Component\Annotation\Plugin\Discovery\AnnotationBridgeDecorator
  3. 11.x core/lib/Drupal/Component/Annotation/Plugin/Discovery/AnnotationBridgeDecorator.php \Drupal\Component\Annotation\Plugin\Discovery\AnnotationBridgeDecorator

Ensures that all definitions are run through the annotation process.

Hierarchy

Expanded class hierarchy of AnnotationBridgeDecorator

3 files declare their use of AnnotationBridgeDecorator
AnnotationBridgeDecoratorTest.php in core/tests/Drupal/Tests/Component/Annotation/Plugin/Discovery/AnnotationBridgeDecoratorTest.php
CKEditor5PluginManager.php in core/modules/ckeditor5/src/Plugin/CKEditor5PluginManager.php
LayoutPluginManager.php in core/lib/Drupal/Core/Layout/LayoutPluginManager.php

File

core/lib/Drupal/Component/Annotation/Plugin/Discovery/AnnotationBridgeDecorator.php, line 11

Namespace

Drupal\Component\Annotation\Plugin\Discovery
View source
class AnnotationBridgeDecorator implements DiscoveryInterface {
    use DiscoveryTrait;
    
    /**
     * The decorated plugin discovery.
     *
     * @var \Drupal\Component\Plugin\Discovery\DiscoveryInterface
     */
    protected $decorated;
    
    /**
     * The name of the annotation that contains the plugin definition.
     *
     * @var string|null
     */
    protected $pluginDefinitionAnnotationName;
    
    /**
     * ObjectDefinitionDiscoveryDecorator constructor.
     *
     * @param \Drupal\Component\Plugin\Discovery\DiscoveryInterface $decorated
     *   The discovery object that is being decorated.
     * @param string $plugin_definition_annotation_name
     *   The name of the annotation that contains the plugin definition. The class
     *   corresponding to this name must implement
     *   \Drupal\Component\Annotation\AnnotationInterface.
     */
    public function __construct(DiscoveryInterface $decorated, $plugin_definition_annotation_name) {
        $this->decorated = $decorated;
        $this->pluginDefinitionAnnotationName = $plugin_definition_annotation_name;
    }
    
    /**
     * {@inheritdoc}
     */
    public function getDefinitions() {
        $definitions = $this->decorated
            ->getDefinitions();
        foreach ($definitions as $id => $definition) {
            // Annotation constructors expect an array of values. If the definition is
            // not an array, it usually means it has been processed already and can be
            // ignored.
            if (is_array($definition)) {
                $definitions[$id] = (new $this->pluginDefinitionAnnotationName($definition))
                    ->get();
            }
        }
        return $definitions;
    }
    
    /**
     * Passes through all unknown calls onto the decorated object.
     *
     * @param string $method
     *   The method to call on the decorated plugin discovery.
     * @param array $args
     *   The arguments to send to the method.
     *
     * @return mixed
     *   The method result.
     */
    public function __call($method, $args) {
        return call_user_func_array([
            $this->decorated,
            $method,
        ], $args);
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title Overrides
AnnotationBridgeDecorator::$decorated protected property The decorated plugin discovery.
AnnotationBridgeDecorator::$pluginDefinitionAnnotationName protected property The name of the annotation that contains the plugin definition.
AnnotationBridgeDecorator::getDefinitions public function Gets the definition of all plugins for this type. Overrides DiscoveryTrait::getDefinitions
AnnotationBridgeDecorator::__call public function Passes through all unknown calls onto the decorated object.
AnnotationBridgeDecorator::__construct public function ObjectDefinitionDiscoveryDecorator constructor.
DiscoveryTrait::doGetDefinition protected function Gets a specific plugin definition.
DiscoveryTrait::getDefinition public function 3
DiscoveryTrait::hasDefinition public function

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.