class AttributeBridgeDecorator

Same name in other branches
  1. 10 core/lib/Drupal/Component/Plugin/Discovery/AttributeBridgeDecorator.php \Drupal\Component\Plugin\Discovery\AttributeBridgeDecorator

Ensures that all definitions are run through the attribute process.

Hierarchy

  • class \Drupal\Component\Plugin\Discovery\AttributeBridgeDecorator implements \Drupal\Component\Plugin\Discovery\DiscoveryInterface uses \Drupal\Component\Plugin\Discovery\DiscoveryTrait

Expanded class hierarchy of AttributeBridgeDecorator

3 files declare their use of AttributeBridgeDecorator
AttributeBridgeDecoratorTest.php in core/tests/Drupal/Tests/Component/Plugin/Discovery/AttributeBridgeDecoratorTest.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/Plugin/Discovery/AttributeBridgeDecorator.php, line 8

Namespace

Drupal\Component\Plugin\Discovery
View source
class AttributeBridgeDecorator implements DiscoveryInterface {
    use DiscoveryTrait;
    
    /**
     * AttributeBridgeDecorator constructor.
     *
     * @param \Drupal\Component\Plugin\Discovery\DiscoveryInterface $decorated
     *   The discovery object that is being decorated.
     * @param string $pluginDefinitionAttributeName
     *   The name of the attribute that contains the plugin definition. The class
     *   corresponding to this name must implement
     *   \Drupal\Component\Plugin\Attribute\AttributeInterface.
     */
    public function __construct(DiscoveryInterface $decorated, string $pluginDefinitionAttributeName) {
    }
    
    /**
     * {@inheritdoc}
     */
    public function getDefinitions() {
        $definitions = $this->decorated
            ->getDefinitions();
        foreach ($definitions as $id => $definition) {
            // Attribute 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)) {
                $class = $definition['class'] ?? NULL;
                $provider = $definition['provider'] ?? NULL;
                unset($definition['class'], $definition['provider']);
                
                /** @var \Drupal\Component\Plugin\Attribute\AttributeInterface $attribute */
                $attribute = new $this->pluginDefinitionAttributeName(...$definition);
                if (isset($class)) {
                    $attribute->setClass($class);
                }
                if (isset($provider)) {
                    $attribute->setProvider($provider);
                }
                $definitions[$id] = $attribute->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 $this->decorated
            ->{$method}(...$args);
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title Overrides
AttributeBridgeDecorator::getDefinitions public function Overrides DiscoveryTrait::getDefinitions
AttributeBridgeDecorator::__call public function Passes through all unknown calls onto the decorated object.
AttributeBridgeDecorator::__construct public function AttributeBridgeDecorator 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.