3 namespace Drupal\Core\Plugin\Context;
5 use Drupal\Core\Plugin\ContextAwarePluginInterface;
8 * Provides an interface for handling sets of contexts.
10 interface ContextHandlerInterface {
13 * Determines plugins whose constraints are satisfied by a set of contexts.
15 * @todo Use context definition objects after
16 * https://www.drupal.org/node/2281635.
18 * @param \Drupal\Component\Plugin\Context\ContextInterface[] $contexts
19 * An array of contexts.
20 * @param array $definitions
21 * An array of plugin definitions.
24 * An array of plugin definitions.
26 public function filterPluginDefinitionsByContexts(array $contexts, array $definitions);
29 * Checks a set of requirements against a set of contexts.
31 * @todo Use context definition objects after
32 * https://www.drupal.org/node/2281635.
34 * @param \Drupal\Component\Plugin\Context\ContextInterface[] $contexts
35 * An array of available contexts.
36 * @param \Drupal\Core\TypedData\DataDefinitionInterface[] $requirements
37 * An array of requirements.
40 * TRUE if all of the requirements are satisfied by the context, FALSE
43 public function checkRequirements(array $contexts, array $requirements);
46 * Determines which contexts satisfy the constraints of a given definition.
48 * @todo Use context definition objects after
49 * https://www.drupal.org/node/2281635.
51 * @param \Drupal\Component\Plugin\Context\ContextInterface[] $contexts
52 * An array of contexts.
53 * @param \Drupal\Core\Plugin\Context\ContextDefinitionInterface $definition
54 * The definition to satisfy.
56 * @return \Drupal\Component\Plugin\Context\ContextInterface[]
57 * An array of matching contexts.
59 public function getMatchingContexts(array $contexts, ContextDefinitionInterface $definition);
62 * Prepares a plugin for evaluation.
64 * @param \Drupal\Core\Plugin\ContextAwarePluginInterface $plugin
65 * A plugin about to be evaluated.
66 * @param \Drupal\Core\Plugin\Context\ContextInterface[] $contexts
67 * An array of contexts to set on the plugin. They will only be set if they
68 * match the plugin's context definitions.
69 * @param array $mappings
70 * (optional) A mapping of the expected assignment names to their context
71 * names. For example, if one of the $contexts is named 'current_user', but the
72 * plugin expects a context named 'user', then this map would contain
73 * 'user' => 'current_user'.
75 * @throws \Drupal\Component\Plugin\Exception\ContextException
76 * Thrown when a context assignment was not satisfied.
78 public function applyContextMapping(ContextAwarePluginInterface $plugin, $contexts, $mappings = []);