trait ContextAwarePluginManagerTrait

Same name in other branches
  1. 9 core/lib/Drupal/Core/Plugin/Context/ContextAwarePluginManagerTrait.php \Drupal\Core\Plugin\Context\ContextAwarePluginManagerTrait
  2. 10 core/lib/Drupal/Core/Plugin/Context/ContextAwarePluginManagerTrait.php \Drupal\Core\Plugin\Context\ContextAwarePluginManagerTrait
  3. 11.x 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

Title Sort descending Modifiers Object type Summary Overrides
ContextAwarePluginManagerTrait::contextHandler protected function Wraps the context handler. 1
ContextAwarePluginManagerTrait::getDefinitions abstract public function See \Drupal\Component\Plugin\Discovery\DiscoveryInterface::getDefinitions(). 1
ContextAwarePluginManagerTrait::getDefinitionsForContexts public function See \Drupal\Core\Plugin\Context\ContextAwarePluginManagerInterface::getDefinitionsForContexts().

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