Version 1
[yaffs-website] / web / core / lib / Drupal / Core / Plugin / Context / ContextHandlerInterface.php
1 <?php
2
3 namespace Drupal\Core\Plugin\Context;
4
5 use Drupal\Core\Plugin\ContextAwarePluginInterface;
6
7 /**
8  * Provides an interface for handling sets of contexts.
9  */
10 interface ContextHandlerInterface {
11
12   /**
13    * Determines plugins whose constraints are satisfied by a set of contexts.
14    *
15    * @todo Use context definition objects after
16    *   https://www.drupal.org/node/2281635.
17    *
18    * @param \Drupal\Component\Plugin\Context\ContextInterface[] $contexts
19    *   An array of contexts.
20    * @param array $definitions
21    *   An array of plugin definitions.
22    *
23    * @return array
24    *   An array of plugin definitions.
25    */
26   public function filterPluginDefinitionsByContexts(array $contexts, array $definitions);
27
28   /**
29    * Checks a set of requirements against a set of contexts.
30    *
31    * @todo Use context definition objects after
32    *   https://www.drupal.org/node/2281635.
33    *
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.
38    *
39    * @return bool
40    *   TRUE if all of the requirements are satisfied by the context, FALSE
41    *   otherwise.
42    */
43   public function checkRequirements(array $contexts, array $requirements);
44
45   /**
46    * Determines which contexts satisfy the constraints of a given definition.
47    *
48    * @todo Use context definition objects after
49    *   https://www.drupal.org/node/2281635.
50    *
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.
55    *
56    * @return \Drupal\Component\Plugin\Context\ContextInterface[]
57    *   An array of matching contexts.
58    */
59   public function getMatchingContexts(array $contexts, ContextDefinitionInterface $definition);
60
61   /**
62    * Prepares a plugin for evaluation.
63    *
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'.
74    *
75    * @throws \Drupal\Component\Plugin\Exception\ContextException
76    *   Thrown when a context assignment was not satisfied.
77    */
78   public function applyContextMapping(ContextAwarePluginInterface $plugin, $contexts, $mappings = []);
79
80 }