ContextAwarePluginManagerTrait.php

Same filename and directory in other branches
  1. 9 core/lib/Drupal/Core/Plugin/Context/ContextAwarePluginManagerTrait.php
  2. 8.9.x core/lib/Drupal/Core/Plugin/Context/ContextAwarePluginManagerTrait.php
  3. 10 core/lib/Drupal/Core/Plugin/Context/ContextAwarePluginManagerTrait.php

Namespace

Drupal\Core\Plugin\Context

File

core/lib/Drupal/Core/Plugin/Context/ContextAwarePluginManagerTrait.php

View source
<?php

namespace Drupal\Core\Plugin\Context;


/**
 * Provides a trait for plugin managers that support context-aware plugins.
 */
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();

}

Traits

Title Deprecated Summary
ContextAwarePluginManagerTrait Provides a trait for plugin managers that support context-aware plugins.

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