class HookDiscovery

Provides a hook-based plugin discovery class.

Hierarchy

Expanded class hierarchy of HookDiscovery

1 file declares its use of HookDiscovery
TypedDataManager.php in drupal/core/lib/Drupal/Core/TypedData/TypedDataManager.php
Contains \Drupal\Core\TypedData\TypedDataManager.

File

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

Namespace

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

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

  /**
   * Constructs a Drupal\Core\Plugin\Discovery\HookDiscovery object.
   *
   * @param string $hook
   *   The Drupal hook that a module can implement in order to interface to
   *   this discovery class.
   */
  function __construct($hook) {
    $this->hook = $hook;
  }

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

  /**
   * Implements Drupal\Component\Plugin\Discovery\DicoveryInterface::getDefinitions().
   */
  public function getDefinitions() {
    $definitions = array();
    foreach (module_implements($this->hook) as $module) {
      $function = $module . '_' . $this->hook;
      foreach ($function() as $plugin_id => $definition) {
        $definition['module'] = $module;
        $definitions[$plugin_id] = $definition;
      }
    }
    return $definitions;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
HookDiscovery::$hook protected property The name of the hook that will be implemented by this discovery instance.
HookDiscovery::getDefinition public function Implements Drupal\Component\Plugin\Discovery\DicoveryInterface::getDefinition(). Overrides DiscoveryInterface::getDefinition
HookDiscovery::getDefinitions public function Implements Drupal\Component\Plugin\Discovery\DicoveryInterface::getDefinitions(). Overrides DiscoveryInterface::getDefinitions
HookDiscovery::__construct function Constructs a Drupal\Core\Plugin\Discovery\HookDiscovery object.