class ViewsHandlerDiscovery

Defines a discovery mechanism to find Views handlers in PSR-0 namespaces.

Hierarchy

Expanded class hierarchy of ViewsHandlerDiscovery

1 file declares its use of ViewsHandlerDiscovery
ViewsHandlerManager.php in drupal/core/modules/views/lib/Drupal/views/Plugin/ViewsHandlerManager.php
Contains \Drupal\views\Plugin\ViewsHandlerManager.

File

drupal/core/modules/views/lib/Drupal/views/Plugin/Discovery/ViewsHandlerDiscovery.php, line 15
Contains \Drupal\views\Plugin\Discovery\ViewsHandlerDiscovery.

Namespace

Drupal\views\Plugin\Discovery
View source
class ViewsHandlerDiscovery extends AnnotatedClassDiscovery {

  /**
   * The type of handler being discovered.
   *
   * @var string
   */
  protected $type;

  /**
   * An object containing the namespaces to look for plugin implementations.
   *
   * @var \Traversable
   */
  protected $rootNamespacesIterator;

  /**
   * Constructs a ViewsHandlerDiscovery object.
   *
   * @param string $type
   *   The plugin type, for example filter.
   * @param \Traversable $root_namespaces
   *   An object that implements \Traversable which contains the root paths
   *   keyed by the corresponding namespace to look for plugin implementations,
   */
  function __construct($type, \Traversable $root_namespaces) {
    $this->type = $type;
    $this->rootNamespacesIterator = $root_namespaces;
    $annotation_namespaces = array(
      'Drupal\\Component\\Annotation' => DRUPAL_ROOT . '/core/lib',
    );
    $plugin_namespaces = array();
    foreach ($root_namespaces as $namespace => $dir) {
      $plugin_namespaces["{$namespace}\\Plugin\\views\\{$type}"] = array(
        $dir,
      );
    }
    parent::__construct($plugin_namespaces, $annotation_namespaces, 'Drupal\\Component\\Annotation\\PluginID');
  }

  /**
   * {@inheritdoc}
   */
  public function getDefinitions() {

    // Add the plugin_type to the definition.
    $definitions = parent::getDefinitions();
    foreach ($definitions as $key => $definition) {
      $definitions[$key]['plugin_type'] = $this->type;
    }
    return $definitions;
  }

  /**
   * {@inheritdoc}
   */
  protected function getPluginNamespaces() {
    $plugin_namespaces = array();
    foreach ($this->rootNamespacesIterator as $namespace => $dir) {
      $plugin_namespaces["{$namespace}\\Plugin\\views\\{$this->type}"] = array(
        $dir,
      );
    }
    return $plugin_namespaces;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
AnnotatedClassDiscovery::$annotationNamespaces protected property The namespaces of classes that can be used as annotations.
AnnotatedClassDiscovery::$pluginDefinitionAnnotationName protected property The name of the annotation that contains the plugin definition.
AnnotatedClassDiscovery::$pluginNamespaces protected property The namespaces within which to find plugin classes.
AnnotatedClassDiscovery::getAnnotationNamespaces protected function Returns an array of PSR-0 namespaces to search for annotation classes.
AnnotatedClassDiscovery::getDefinition public function Implements Drupal\Component\Plugin\Discovery\DiscoveryInterface::getDefinition(). Overrides DiscoveryInterface::getDefinition
ViewsHandlerDiscovery::$rootNamespacesIterator protected property An object containing the namespaces to look for plugin implementations.
ViewsHandlerDiscovery::$type protected property The type of handler being discovered.
ViewsHandlerDiscovery::getDefinitions public function Implements Drupal\Component\Plugin\Discovery\DiscoveryInterface::getDefinitions(). Overrides AnnotatedClassDiscovery::getDefinitions
ViewsHandlerDiscovery::getPluginNamespaces protected function Returns an array of PSR-0 namespaces to search for plugin classes. Overrides AnnotatedClassDiscovery::getPluginNamespaces
ViewsHandlerDiscovery::__construct function Constructs a ViewsHandlerDiscovery object. Overrides AnnotatedClassDiscovery::__construct