class InfoHookDecorator

Allows info hook implementations to enhance discovered plugin definitions.

Hierarchy

Expanded class hierarchy of InfoHookDecorator

1 file declares its use of InfoHookDecorator
EntityManager.php in drupal/core/lib/Drupal/Core/Entity/EntityManager.php
Contains \Drupal\Core\Entity\EntityManager.

File

drupal/core/lib/Drupal/Core/Plugin/Discovery/InfoHookDecorator.php, line 15
Contains Drupal\Core\Plugin\Discovery\InfoHookDecorator.

Namespace

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

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

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

  /**
   * Constructs a InfoHookDecorator object.
   *
   * @param Drupal\Component\Plugin\Discovery\DiscoveryInterface $decorated
   *   The object implementing DiscoveryInterface that is being decorated.
   * @param string $hook
   *   The name of the info hook to be invoked 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();
    foreach (module_implements($this->hook) as $module) {
      $function = $module . '_' . $this->hook;
      $function($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
InfoHookDecorator::$decorated protected property The Discovery object being decorated.
InfoHookDecorator::$hook protected property The name of the info hook that will be implemented by this discovery instance.
InfoHookDecorator::getDefinition public function Implements Drupal\Component\Plugin\Discovery\DiscoveryInterface::getDefinition(). Overrides DiscoveryInterface::getDefinition
InfoHookDecorator::getDefinitions public function Implements Drupal\Component\Plugin\Discovery\DiscoveryInterface::getDefinitions(). Overrides DiscoveryInterface::getDefinitions
InfoHookDecorator::__call public function Passes through all unknown calls onto the decorated object.
InfoHookDecorator::__construct public function Constructs a InfoHookDecorator object.