trait 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
   *   The context handler service.
   */
  protected function contextHandler() {
    return \Drupal::service('context.handler');
  }
  
  /**
   * Determines plugins whose constraints are satisfied by a set of contexts.
   *
   * @see \Drupal\Core\Plugin\Context\ContextAwarePluginManagerInterface::getDefinitionsForContexts()
   */
  public function getDefinitionsForContexts(array $contexts = []) {
    return $this->contextHandler()
      ->filterPluginDefinitionsByContexts($contexts, $this->getDefinitions());
  }
  
  /**
   * Gets a specific plugin definition.
   *
   * @see \Drupal\Component\Plugin\Discovery\DiscoveryInterface::getDefinitions()
   */
  abstract public function getDefinitions();

}

Members

Title Sort descending Modifiers Object type Summary Overrides
ContextAwarePluginManagerTrait::contextHandler protected function Wraps the context handler. 1
ContextAwarePluginManagerTrait::getDefinitions abstract public function Gets a specific plugin definition. 1
ContextAwarePluginManagerTrait::getDefinitionsForContexts public function Determines plugins whose constraints are satisfied by a set of contexts.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.