class AlterDecorator

Enables altering of discovered plugin definitions.

Hierarchy

Expanded class hierarchy of AlterDecorator

18 files declare their use of AlterDecorator
ActionManager.php in drupal/core/lib/Drupal/Core/Action/ActionManager.php
Contains \Drupal\Core\Action\ActionManager.
AlterDecoratorTestPluginManager.php in drupal/core/modules/system/tests/modules/plugin_test/lib/Drupal/plugin_test/Plugin/AlterDecoratorTestPluginManager.php
Definition of Drupal\plugin_test\Plugin\plugin_test\AlterDecoratorTestPluginManager.
ArchiverManager.php in drupal/core/lib/Drupal/Core/Archiver/ArchiverManager.php
BlockManager.php in drupal/core/modules/block/lib/Drupal/block/Plugin/Type/BlockManager.php
CKEditorPluginManager.php in drupal/core/modules/ckeditor/lib/Drupal/ckeditor/CKEditorPluginManager.php
Contains \Drupal\ckeditor\CKEditorPluginManager.

... See full list

1 string reference to 'AlterDecorator'
AlterDecoratorTest::getInfo in drupal/core/modules/system/lib/Drupal/system/Tests/Plugin/AlterDecoratorTest.php

File

drupal/core/lib/Drupal/Core/Plugin/Discovery/AlterDecorator.php, line 15
Definition of Drupal\Core\Plugin\Discovery\AlterDiscoveryDecorator.

Namespace

Drupal\Core\Plugin\Discovery
View source
class AlterDecorator implements DiscoveryInterface {

  /**
   * The name of the alter hook that will be implemented by this discovery instance.
   *
   * @var string
   */
  protected $hook;

  /**
   * The Discovery object being decorated.
   *
   * @var Drupal\Component\Plugin\Discovery\DiscoveryInterface
   */
  protected $decorated;

  /**
   * Constructs a Drupal\Core\Plugin\Discovery\AlterDecorator object.
   *
   * It uses the DiscoveryInterface object it should decorate.
   *
   * @param Drupal\Component\Plugin\Discovery\DiscoveryInterface $decorated
   *   The object implementing DiscoveryInterface that is being decorated.
   * @param string $hook
   *   The name of the alter hook that will be used by this discovery instance.
   */
  public function __construct(DiscoveryInterface $decorated, $hook) {
    $this->decorated = $decorated;
    $this->hook = $hook;
  }

  /**
   * Implements Drupal\Component\Plugin\Discovery\DiscoveryInterface::getDefinition().
   */
  public function getDefinition($plugin_id) {
    $definitions = $this
      ->getDefinitions();
    return isset($definitions[$plugin_id]) ? $definitions[$plugin_id] : NULL;
  }

  /**
   * Implements Drupal\Component\Plugin\Discovery\DiscoveryInterface::getDefinitions().
   */
  public function getDefinitions() {
    $definitions = $this->decorated
      ->getDefinitions();
    drupal_alter($this->hook, $definitions);
    return $definitions;
  }

  /**
   * Passes through all unknown calls onto the decorated object.
   */
  public function __call($method, $args) {
    return call_user_func_array(array(
      $this->decorated,
      $method,
    ), $args);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
AlterDecorator::$decorated protected property The Discovery object being decorated.
AlterDecorator::$hook protected property The name of the alter hook that will be implemented by this discovery instance.
AlterDecorator::getDefinition public function Implements Drupal\Component\Plugin\Discovery\DiscoveryInterface::getDefinition(). Overrides DiscoveryInterface::getDefinition
AlterDecorator::getDefinitions public function Implements Drupal\Component\Plugin\Discovery\DiscoveryInterface::getDefinitions(). Overrides DiscoveryInterface::getDefinitions
AlterDecorator::__call public function Passes through all unknown calls onto the decorated object.
AlterDecorator::__construct public function Constructs a Drupal\Core\Plugin\Discovery\AlterDecorator object.