-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathContextAwarePluginInterface.php
147 lines (132 loc) · 4.26 KB
/
ContextAwarePluginInterface.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
<?php
namespace Drupal\Component\Plugin;
use Drupal\Component\Plugin\Context\ContextInterface;
/**
* Interface for defining context aware plugins.
*
* Context aware plugins can specify an array of context definitions keyed by
* context name at the plugin definition under the "context" key.
*
* @ingroup plugin_api
*/
interface ContextAwarePluginInterface extends PluginInspectionInterface {
/**
* Gets the context definitions of the plugin.
*
* @return \Drupal\Component\Plugin\Context\ContextDefinitionInterface[]
* The array of context definitions, keyed by context name.
*/
public function getContextDefinitions();
/**
* Gets a specific context definition of the plugin.
*
* @param string $name
* The name of the context in the plugin definition.
*
* @return \Drupal\Component\Plugin\Context\ContextDefinitionInterface
* The definition against which the context value must validate.
*
* @throws \Drupal\Component\Plugin\Exception\ContextException
* If the requested context is not defined.
*/
public function getContextDefinition($name);
/**
* Gets the defined contexts.
*
* @return array
* The set context objects.
*
* @throws \Drupal\Component\Plugin\Exception\ContextException
* If contexts are defined but not set.
*/
public function getContexts();
/**
* Gets a defined context.
*
* @param string $name
* The name of the context in the plugin definition.
*
* @return \Drupal\Component\Plugin\Context\ContextInterface
* The context object.
*
* @throws \Drupal\Component\Plugin\Exception\ContextException
* If the requested context is not set.
*/
public function getContext($name);
/**
* Gets the values for all defined contexts.
*
* @return array
* An array of set context values, keyed by context name. If a context is
* unset its value is returned as NULL.
*/
public function getContextValues();
/**
* Gets the value for a defined context.
*
* @param string $name
* The name of the context in the plugin configuration.
*
* @return mixed
* The currently set context value.
*
* @throws \Drupal\Component\Plugin\Exception\ContextException
* If the requested context is not set.
*/
public function getContextValue($name);
/**
* Set a context on this plugin.
*
* @param string $name
* The name of the context in the plugin configuration.
* @param \Drupal\Component\Plugin\Context\ContextInterface $context
* The context object to set.
*/
public function setContext($name, ContextInterface $context);
/**
* Sets the value for a defined context.
*
* @param string $name
* The name of the context in the plugin definition.
* @param mixed $value
* The value to set the context to. The value has to validate against the
* provided context definition.
*
* @return $this
* A context aware plugin object for chaining.
*
* @throws \Drupal\Component\Plugin\Exception\ContextException
* If the value does not pass validation.
*/
public function setContextValue($name, $value);
/**
* Validates the set values for the defined contexts.
*
* @return \Symfony\Component\Validator\ConstraintViolationListInterface
* A list of constraint violations. If the list is empty, validation
* succeeded.
*/
public function validateContexts();
/**
* Gets a mapping of the expected assignment names to their context names.
*
* @return array
* A mapping of the expected assignment names to their context names. For
* example, if one of the $contexts is named 'user.current_user', but the
* plugin expects a context named 'user', then this map would contain
* 'user' => 'user.current_user'.
*/
public function getContextMapping();
/**
* Sets a mapping of the expected assignment names to their context names.
*
* @param array $context_mapping
* A mapping of the expected assignment names to their context names. For
* example, if one of the $contexts is named 'user.current_user', but the
* plugin expects a context named 'user', then this map would contain
* 'user' => 'user.current_user'.
*
* @return $this
*/
public function setContextMapping(array $context_mapping);
}