3 namespace Drupal\Core\Plugin\Context;
6 * Provides a trait for plugin managers that support context-aware plugins.
8 trait ContextAwarePluginManagerTrait {
11 * Wraps the context handler.
13 * @return \Drupal\Core\Plugin\Context\ContextHandlerInterface
15 protected function contextHandler() {
16 return \Drupal::service('context.handler');
20 * See \Drupal\Core\Plugin\Context\ContextAwarePluginManagerInterface::getDefinitionsForContexts().
22 public function getDefinitionsForContexts(array $contexts = []) {
23 return $this->contextHandler()->filterPluginDefinitionsByContexts($contexts, $this->getDefinitions());
27 * See \Drupal\Component\Plugin\Discovery\DiscoveryInterface::getDefinitions().
29 abstract public function getDefinitions();