You are here

trait ContextAwarePluginManagerTrait in Drupal 8

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/Plugin/Context/ContextAwarePluginManagerTrait.php \Drupal\Core\Plugin\Context\ContextAwarePluginManagerTrait

Provides a trait for plugin managers that support context-aware plugins.

Hierarchy

1 file declares its use of ContextAwarePluginManagerTrait
FilteredPluginManagerTrait.php in core/lib/Drupal/Core/Plugin/FilteredPluginManagerTrait.php

File

core/lib/Drupal/Core/Plugin/Context/ContextAwarePluginManagerTrait.php, line 8

Namespace

Drupal\Core\Plugin\Context
View source
trait ContextAwarePluginManagerTrait {

  /**
   * Wraps the context handler.
   *
   * @return \Drupal\Core\Plugin\Context\ContextHandlerInterface
   */
  protected function contextHandler() {
    return \Drupal::service('context.handler');
  }

  /**
   * See \Drupal\Core\Plugin\Context\ContextAwarePluginManagerInterface::getDefinitionsForContexts().
   */
  public function getDefinitionsForContexts(array $contexts = []) {
    return $this
      ->contextHandler()
      ->filterPluginDefinitionsByContexts($contexts, $this
      ->getDefinitions());
  }

  /**
   * See \Drupal\Component\Plugin\Discovery\DiscoveryInterface::getDefinitions().
   */
  public abstract function getDefinitions();

}

Members