class StaticDiscoveryDecorator

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

A decorator that allows manual registration of undiscoverable definitions.

Hierarchy

Expanded class hierarchy of StaticDiscoveryDecorator

2 files declare their use of StaticDiscoveryDecorator
ConstraintManager.php in core/lib/Drupal/Core/Validation/ConstraintManager.php
StaticDiscoveryDecoratorTest.php in core/tests/Drupal/Tests/Component/Plugin/Discovery/StaticDiscoveryDecoratorTest.php

File

core/lib/Drupal/Component/Plugin/Discovery/StaticDiscoveryDecorator.php, line 8

Namespace

Drupal\Component\Plugin\Discovery
View source
class StaticDiscoveryDecorator extends StaticDiscovery {
    
    /**
     * The Discovery object being decorated.
     *
     * @var \Drupal\Component\Plugin\Discovery\DiscoveryInterface
     */
    protected $decorated;
    
    /**
     * A callback or closure used for registering additional definitions.
     *
     * @var callable
     */
    protected $registerDefinitions;
    
    /**
     * Constructs a \Drupal\Component\Plugin\Discovery\StaticDiscoveryDecorator object.
     *
     * @param \Drupal\Component\Plugin\Discovery\DiscoveryInterface $decorated
     *   The discovery object that is being decorated.
     * @param callable|null $registerDefinitions
     *   (optional) A callback or closure used for registering additional
     *   definitions.
     */
    public function __construct(DiscoveryInterface $decorated, $registerDefinitions = NULL) {
        $this->decorated = $decorated;
        $this->registerDefinitions = $registerDefinitions;
    }
    
    /**
     * {@inheritdoc}
     */
    public function getDefinition($base_plugin_id, $exception_on_invalid = TRUE) {
        if (isset($this->registerDefinitions)) {
            call_user_func($this->registerDefinitions);
        }
        $this->definitions += $this->decorated
            ->getDefinitions();
        return parent::getDefinition($base_plugin_id, $exception_on_invalid);
    }
    
    /**
     * {@inheritdoc}
     */
    public function getDefinitions() {
        if (isset($this->registerDefinitions)) {
            call_user_func($this->registerDefinitions);
        }
        $this->definitions += $this->decorated
            ->getDefinitions();
        return parent::getDefinitions();
    }
    
    /**
     * Passes through all unknown calls onto the decorated object.
     */
    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
DiscoveryCachedTrait::$definitions protected property Cached definitions array. 1
DiscoveryTrait::doGetDefinition protected function Gets a specific plugin definition.
DiscoveryTrait::hasDefinition public function
StaticDiscovery::deleteDefinition public function Deletes a plugin definition.
StaticDiscovery::setDefinition public function Sets a plugin definition.
StaticDiscoveryDecorator::$decorated protected property The Discovery object being decorated.
StaticDiscoveryDecorator::$registerDefinitions protected property A callback or closure used for registering additional definitions.
StaticDiscoveryDecorator::getDefinition public function Overrides DiscoveryCachedTrait::getDefinition
StaticDiscoveryDecorator::getDefinitions public function Gets the definition of all plugins for this type. Overrides StaticDiscovery::getDefinitions
StaticDiscoveryDecorator::__call public function Passes through all unknown calls onto the decorated object.
StaticDiscoveryDecorator::__construct public function Constructs a \Drupal\Component\Plugin\Discovery\StaticDiscoveryDecorator object.

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