Chris@0
|
1 <?php
|
Chris@0
|
2
|
Chris@0
|
3 namespace Drupal\Component\Plugin\Context;
|
Chris@0
|
4
|
Chris@0
|
5 /**
|
Chris@0
|
6 * Interface used to define definition objects found in ContextInterface.
|
Chris@0
|
7 *
|
Chris@0
|
8 * @see \Drupal\Component\Plugin\Context\ContextInterface
|
Chris@0
|
9 *
|
Chris@0
|
10 * @todo WARNING: This interface is going to receive some additions as part of
|
Chris@0
|
11 * https://www.drupal.org/node/2346999.
|
Chris@0
|
12 */
|
Chris@0
|
13 interface ContextDefinitionInterface {
|
Chris@0
|
14
|
Chris@0
|
15 /**
|
Chris@0
|
16 * Gets a human readable label.
|
Chris@0
|
17 *
|
Chris@0
|
18 * @return string
|
Chris@0
|
19 * The label.
|
Chris@0
|
20 */
|
Chris@0
|
21 public function getLabel();
|
Chris@0
|
22
|
Chris@0
|
23 /**
|
Chris@0
|
24 * Sets the human readable label.
|
Chris@0
|
25 *
|
Chris@0
|
26 * @param string $label
|
Chris@0
|
27 * The label to set.
|
Chris@0
|
28 *
|
Chris@0
|
29 * @return $this
|
Chris@0
|
30 */
|
Chris@0
|
31 public function setLabel($label);
|
Chris@0
|
32
|
Chris@0
|
33 /**
|
Chris@0
|
34 * Gets a human readable description.
|
Chris@0
|
35 *
|
Chris@0
|
36 * @return string|null
|
Chris@0
|
37 * The description, or NULL if no description is available.
|
Chris@0
|
38 */
|
Chris@0
|
39 public function getDescription();
|
Chris@0
|
40
|
Chris@0
|
41 /**
|
Chris@0
|
42 * Sets the human readable description.
|
Chris@0
|
43 *
|
Chris@0
|
44 * @param string|null $description
|
Chris@0
|
45 * The description to set.
|
Chris@0
|
46 *
|
Chris@0
|
47 * @return $this
|
Chris@0
|
48 */
|
Chris@0
|
49 public function setDescription($description);
|
Chris@0
|
50
|
Chris@0
|
51 /**
|
Chris@0
|
52 * Gets the data type needed by the context.
|
Chris@0
|
53 *
|
Chris@0
|
54 * If the context is multiple-valued, this represents the type of each value.
|
Chris@0
|
55 *
|
Chris@0
|
56 * @return string
|
Chris@0
|
57 * The data type.
|
Chris@0
|
58 */
|
Chris@0
|
59 public function getDataType();
|
Chris@0
|
60
|
Chris@0
|
61 /**
|
Chris@0
|
62 * Sets the data type needed by the context.
|
Chris@0
|
63 *
|
Chris@0
|
64 * @param string $data_type
|
Chris@0
|
65 * The data type to set.
|
Chris@0
|
66 *
|
Chris@0
|
67 * @return $this
|
Chris@0
|
68 */
|
Chris@0
|
69 public function setDataType($data_type);
|
Chris@0
|
70
|
Chris@0
|
71 /**
|
Chris@0
|
72 * Determines whether the data is multi-valued, i.e. a list of data items.
|
Chris@0
|
73 *
|
Chris@0
|
74 * @return bool
|
Chris@0
|
75 * Whether the data is multi-valued; i.e. a list of data items.
|
Chris@0
|
76 */
|
Chris@0
|
77 public function isMultiple();
|
Chris@0
|
78
|
Chris@0
|
79 /**
|
Chris@0
|
80 * Sets whether the data is multi-valued.
|
Chris@0
|
81 *
|
Chris@0
|
82 * @param bool $multiple
|
Chris@0
|
83 * (optional) Whether the data is multi-valued. Defaults to TRUE.
|
Chris@0
|
84 *
|
Chris@0
|
85 * @return $this
|
Chris@0
|
86 */
|
Chris@0
|
87 public function setMultiple($multiple = TRUE);
|
Chris@0
|
88
|
Chris@0
|
89 /**
|
Chris@0
|
90 * Determines whether the context is required.
|
Chris@0
|
91 *
|
Chris@0
|
92 * For required data a non-NULL value is mandatory.
|
Chris@0
|
93 *
|
Chris@0
|
94 * @return bool
|
Chris@0
|
95 * Whether a data value is required.
|
Chris@0
|
96 */
|
Chris@0
|
97 public function isRequired();
|
Chris@0
|
98
|
Chris@0
|
99 /**
|
Chris@0
|
100 * Sets whether the data is required.
|
Chris@0
|
101 *
|
Chris@0
|
102 * @param bool $required
|
Chris@0
|
103 * (optional) Whether the data is multi-valued. Defaults to TRUE.
|
Chris@0
|
104 *
|
Chris@0
|
105 * @return $this
|
Chris@0
|
106 */
|
Chris@0
|
107 public function setRequired($required = TRUE);
|
Chris@0
|
108
|
Chris@0
|
109 /**
|
Chris@0
|
110 * Gets the default value for this context definition.
|
Chris@0
|
111 *
|
Chris@0
|
112 * @return mixed
|
Chris@0
|
113 * The default value or NULL if no default value is set.
|
Chris@0
|
114 */
|
Chris@0
|
115 public function getDefaultValue();
|
Chris@0
|
116
|
Chris@0
|
117 /**
|
Chris@0
|
118 * Sets the default data value.
|
Chris@0
|
119 *
|
Chris@0
|
120 * @param mixed $default_value
|
Chris@0
|
121 * The default value to be set or NULL to remove any default value.
|
Chris@0
|
122 *
|
Chris@0
|
123 * @return $this
|
Chris@0
|
124 */
|
Chris@0
|
125 public function setDefaultValue($default_value);
|
Chris@0
|
126
|
Chris@0
|
127 /**
|
Chris@0
|
128 * Gets an array of validation constraints.
|
Chris@0
|
129 *
|
Chris@0
|
130 * @return array
|
Chris@0
|
131 * An array of validation constraint definitions, keyed by constraint name.
|
Chris@0
|
132 * Each constraint definition can be used for instantiating
|
Chris@0
|
133 * \Symfony\Component\Validator\Constraint objects.
|
Chris@0
|
134 */
|
Chris@0
|
135 public function getConstraints();
|
Chris@0
|
136
|
Chris@0
|
137 /**
|
Chris@0
|
138 * Sets the array of validation constraints.
|
Chris@0
|
139 *
|
Chris@0
|
140 * NOTE: This will override any previously set constraints. In most cases
|
Chris@0
|
141 * ContextDefinitionInterface::addConstraint() should be used instead.
|
Chris@0
|
142 *
|
Chris@0
|
143 * @param array $constraints
|
Chris@0
|
144 * The array of constraints.
|
Chris@0
|
145 *
|
Chris@0
|
146 * @return $this
|
Chris@0
|
147 *
|
Chris@0
|
148 * @see self::addConstraint()
|
Chris@0
|
149 */
|
Chris@0
|
150 public function setConstraints(array $constraints);
|
Chris@0
|
151
|
Chris@0
|
152 /**
|
Chris@0
|
153 * Adds a validation constraint.
|
Chris@0
|
154 *
|
Chris@0
|
155 * @param string $constraint_name
|
Chris@0
|
156 * The name of the constraint to add, i.e. its plugin id.
|
Chris@0
|
157 * @param array|null $options
|
Chris@0
|
158 * The constraint options as required by the constraint plugin, or NULL.
|
Chris@0
|
159 *
|
Chris@0
|
160 * @return $this
|
Chris@0
|
161 */
|
Chris@0
|
162 public function addConstraint($constraint_name, $options = NULL);
|
Chris@0
|
163
|
Chris@0
|
164 /**
|
Chris@0
|
165 * Gets a validation constraint.
|
Chris@0
|
166 *
|
Chris@0
|
167 * @param string $constraint_name
|
Chris@0
|
168 * The name of the constraint, i.e. its plugin id.
|
Chris@0
|
169 *
|
Chris@0
|
170 * @return array
|
Chris@0
|
171 * A validation constraint definition which can be used for instantiating a
|
Chris@0
|
172 * \Symfony\Component\Validator\Constraint object.
|
Chris@0
|
173 */
|
Chris@0
|
174 public function getConstraint($constraint_name);
|
Chris@0
|
175
|
Chris@0
|
176 }
|