Same name and namespace in other branches
  1. 8.9.x core/lib/Drupal/Core/Plugin/Context/ContextHandlerInterface.php \Drupal\Core\Plugin\Context\ContextHandlerInterface
  2. 9 core/lib/Drupal/Core/Plugin/Context/ContextHandlerInterface.php \Drupal\Core\Plugin\Context\ContextHandlerInterface

Provides an interface for handling sets of contexts.

Hierarchy

Expanded class hierarchy of ContextHandlerInterface

All classes that implement ContextHandlerInterface

8 files declare their use of ContextHandlerInterface
BlockAccessControlHandler.php in core/modules/block/src/BlockAccessControlHandler.php
BlockComponentRenderArrayTest.php in core/modules/layout_builder/tests/src/Unit/BlockComponentRenderArrayTest.php
BlockRepository.php in core/modules/block/src/BlockRepository.php
FilteredPluginManagerTraitTest.php in core/tests/Drupal/Tests/Core/Plugin/FilteredPluginManagerTraitTest.php
SectionRenderTest.php in core/modules/layout_builder/tests/src/Unit/SectionRenderTest.php

... See full list

File

core/lib/Drupal/Core/Plugin/Context/ContextHandlerInterface.php, line 10

Namespace

Drupal\Core\Plugin\Context
View source
interface ContextHandlerInterface {

  /**
   * Determines plugins whose constraints are satisfied by a set of contexts.
   *
   * @todo Use context definition objects after
   *   https://www.drupal.org/node/2281635.
   *
   * @param \Drupal\Component\Plugin\Context\ContextInterface[] $contexts
   *   An array of contexts.
   * @param array $definitions
   *   An array of plugin definitions.
   *
   * @return array
   *   An array of plugin definitions.
   */
  public function filterPluginDefinitionsByContexts(array $contexts, array $definitions);

  /**
   * Checks a set of requirements against a set of contexts.
   *
   * @todo Use context definition objects after
   *   https://www.drupal.org/node/2281635.
   *
   * @param \Drupal\Component\Plugin\Context\ContextInterface[] $contexts
   *   An array of available contexts.
   * @param \Drupal\Core\TypedData\DataDefinitionInterface[] $requirements
   *   An array of requirements.
   *
   * @return bool
   *   TRUE if all of the requirements are satisfied by the context, FALSE
   *   otherwise.
   */
  public function checkRequirements(array $contexts, array $requirements);

  /**
   * Determines which contexts satisfy the constraints of a given definition.
   *
   * @todo Use context definition objects after
   *   https://www.drupal.org/node/2281635.
   *
   * @param \Drupal\Component\Plugin\Context\ContextInterface[] $contexts
   *   An array of contexts.
   * @param \Drupal\Core\Plugin\Context\ContextDefinitionInterface $definition
   *   The definition to satisfy.
   *
   * @return \Drupal\Component\Plugin\Context\ContextInterface[]
   *   An array of matching contexts.
   */
  public function getMatchingContexts(array $contexts, ContextDefinitionInterface $definition);

  /**
   * Prepares a plugin for evaluation.
   *
   * @param \Drupal\Core\Plugin\ContextAwarePluginInterface $plugin
   *   A plugin about to be evaluated.
   * @param \Drupal\Core\Plugin\Context\ContextInterface[] $contexts
   *   An array of contexts to set on the plugin. They will only be set if they
   *   match the plugin's context definitions.
   * @param array $mappings
   *   (optional) A mapping of the expected assignment names to their context
   *   names. For example, if one of the $contexts is named 'current_user', but the
   *   plugin expects a context named 'user', then this map would contain
   *   'user' => 'current_user'.
   *
   * @throws \Drupal\Component\Plugin\Exception\ContextException
   *   Thrown when a context assignment was not satisfied.
   * @throws \Drupal\Component\Plugin\Exception\MissingValueContextException
   *   Thrown when a context is provided but has no value. Only thrown if
   *   no contexts are missing.
   */
  public function applyContextMapping(ContextAwarePluginInterface $plugin, $contexts, $mappings = []);

}

Members

Namesort descending Modifiers Type Description Overrides
ContextHandlerInterface::applyContextMapping public function Prepares a plugin for evaluation.
ContextHandlerInterface::checkRequirements public function Checks a set of requirements against a set of contexts.
ContextHandlerInterface::filterPluginDefinitionsByContexts public function Determines plugins whose constraints are satisfied by a set of contexts.
ContextHandlerInterface::getMatchingContexts public function Determines which contexts satisfy the constraints of a given definition.