5ef843b4cb3e1c5eab8a4aadab23b3fc66bd3ab5
[yaffs-website] / web / core / modules / workflows / src / WorkflowTypeInterface.php
1 <?php
2
3 namespace Drupal\workflows;
4
5 use Drupal\Component\Plugin\ConfigurablePluginInterface;
6 use Drupal\Component\Plugin\DerivativeInspectionInterface;
7 use Drupal\Core\Plugin\PluginWithFormsInterface;
8
9 /**
10  * An interface for Workflow type plugins.
11  */
12 interface WorkflowTypeInterface extends PluginWithFormsInterface, DerivativeInspectionInterface, ConfigurablePluginInterface {
13
14   /**
15    * The key of the global workflow plugin form.
16    */
17   const PLUGIN_FORM_KEY = 'configure';
18
19   /**
20    * Gets the label for the workflow type.
21    *
22    * @return string
23    *   The workflow type label.
24    */
25   public function label();
26
27   /**
28    * Determines if the workflow is being has data associated with it.
29    *
30    * @internal
31    *   Marked as internal until it's validated this should form part of the
32    *   public API in https://www.drupal.org/node/2897148.
33    *
34    * @param \Drupal\workflows\WorkflowInterface $workflow
35    *   The workflow to check.
36    *
37    * @return bool
38    *   TRUE if the workflow is being used, FALSE if not.
39    */
40   public function workflowHasData(WorkflowInterface $workflow);
41
42   /**
43    * Determines if the workflow state has data associated with it.
44    *
45    * @internal
46    *   Marked as internal until it's validated this should form part of the
47    *   public API in https://www.drupal.org/node/2897148.
48    *
49    * @param \Drupal\workflows\WorkflowInterface $workflow
50    *   The workflow to check.
51    * @param \Drupal\workflows\StateInterface $state
52    *   The workflow state to check.
53    *
54    * @return bool
55    *   TRUE if the workflow state is being used, FALSE if not.
56    */
57   public function workflowStateHasData(WorkflowInterface $workflow, StateInterface $state);
58
59   /**
60    * Gets the initial state for the workflow.
61    *
62    * @return \Drupal\workflows\StateInterface
63    *   The initial state.
64    */
65   public function getInitialState();
66
67   /**
68    * Gets the required states of workflow type.
69    *
70    * This is usually specified in the workflow type annotation.
71    *
72    * @return string[]
73    *   The required states.
74    *
75    * @see \Drupal\workflows\Annotation\WorkflowType
76    */
77   public function getRequiredStates();
78
79   /**
80    * Informs the plugin that a dependency of the workflow will be deleted.
81    *
82    * @param array $dependencies
83    *   An array of dependencies that will be deleted keyed by dependency type.
84    *
85    * @return bool
86    *   TRUE if the workflow settings have been changed, FALSE if not.
87    *
88    * @see \Drupal\Core\Config\ConfigEntityInterface::onDependencyRemoval()
89    *
90    * @todo https://www.drupal.org/node/2579743 make part of a generic interface.
91    */
92   public function onDependencyRemoval(array $dependencies);
93
94   /**
95    * Adds a state to the workflow.
96    *
97    * @param string $state_id
98    *   The state's ID.
99    * @param string $label
100    *   The state's label.
101    *
102    * @return $this
103    *
104    * @throws \InvalidArgumentException
105    *   Thrown if a state already exists or state ID is invalid.
106    */
107   public function addState($state_id, $label);
108
109   /**
110    * Determines if the workflow has a state with the provided ID.
111    *
112    * @param string $state_id
113    *   The state's ID.
114    *
115    * @return bool
116    *   TRUE if the workflow has a state with the provided ID, FALSE if not.
117    */
118   public function hasState($state_id);
119
120   /**
121    * Gets state objects for the provided state IDs.
122    *
123    * @param string[] $state_ids
124    *   A list of state IDs to get. If NULL then all states will be returned.
125    *
126    * @return \Drupal\workflows\StateInterface[]
127    *   An array of workflow states.
128    *
129    * @throws \InvalidArgumentException
130    *   Thrown if $state_ids contains a state ID that does not exist.
131    */
132   public function getStates($state_ids = NULL);
133
134   /**
135    * Gets a workflow state.
136    *
137    * @param string $state_id
138    *   The state's ID.
139    *
140    * @return \Drupal\workflows\StateInterface
141    *   The workflow state.
142    *
143    * @throws \InvalidArgumentException
144    *   Thrown if $state_id does not exist.
145    */
146   public function getState($state_id);
147
148   /**
149    * Sets a state's label.
150    *
151    * @param string $state_id
152    *   The state ID to set the label for.
153    * @param string $label
154    *   The state's label.
155    *
156    * @return $this
157    */
158   public function setStateLabel($state_id, $label);
159
160   /**
161    * Sets a state's weight value.
162    *
163    * @param string $state_id
164    *   The state ID to set the weight for.
165    * @param int $weight
166    *   The state's weight.
167    *
168    * @return $this
169    */
170   public function setStateWeight($state_id, $weight);
171
172   /**
173    * Deletes a state from the workflow.
174    *
175    * @param string $state_id
176    *   The state ID to delete.
177    *
178    * @return \Drupal\workflows\WorkflowTypeInterface
179    *   The workflow type plugin.
180    *
181    * @throws \InvalidArgumentException
182    *   Thrown if $state_id does not exist.
183    */
184   public function deleteState($state_id);
185
186   /**
187    * Adds a transition to the workflow.
188    *
189    * @param string $id
190    *   The transition ID.
191    * @param string $label
192    *   The transition's label.
193    * @param array $from_state_ids
194    *   The state IDs to transition from.
195    * @param string $to_state_id
196    *   The state ID to transition to.
197    *
198    * @return $this
199    *
200    * @throws \InvalidArgumentException
201    *   Thrown if either state does not exist.
202    */
203   public function addTransition($id, $label, array $from_state_ids, $to_state_id);
204
205   /**
206    * Gets a transition object for the provided transition ID.
207    *
208    * @param string $transition_id
209    *   A transition ID.
210    *
211    * @return \Drupal\workflows\TransitionInterface
212    *   The transition.
213    *
214    * @throws \InvalidArgumentException
215    *   Thrown if $transition_id does not exist.
216    */
217   public function getTransition($transition_id);
218
219   /**
220    * Determines if a transition exists.
221    *
222    * @param string $transition_id
223    *   The transition ID.
224    *
225    * @return bool
226    *   TRUE if the transition exists, FALSE if not.
227    */
228   public function hasTransition($transition_id);
229
230   /**
231    * Gets transition objects for the provided transition IDs.
232    *
233    * @param string[] $transition_ids
234    *   A list of transition IDs to get. If NULL then all transitions will be
235    *   returned.
236    *
237    * @return \Drupal\workflows\TransitionInterface[]
238    *   An array of transition objects.
239    *
240    * @throws \InvalidArgumentException
241    *   Thrown if $transition_ids contains a transition ID that does not exist.
242    */
243   public function getTransitions(array $transition_ids = NULL);
244
245   /**
246    * Gets the transition IDs for a state for the provided direction.
247    *
248    * @param $state_id
249    *   The state to get transitions for.
250    * @param string $direction
251    *   (optional) The direction of the transition. Defaults to 'from'. Possible
252    *   values are: 'from' and 'to'.
253    *
254    * @return array
255    *   The transition IDs for a state for the provided direction.
256    */
257   public function getTransitionsForState($state_id, $direction = 'from');
258
259   /**
260    * Gets a transition from state to state.
261    *
262    * @param string $from_state_id
263    *   The state ID to transition from.
264    * @param string $to_state_id
265    *   The state ID to transition to.
266    *
267    * @return \Drupal\workflows\TransitionInterface
268    *   The transitions.
269    *
270    * @throws \InvalidArgumentException
271    *   Thrown if the transition does not exist.
272    */
273   public function getTransitionFromStateToState($from_state_id, $to_state_id);
274
275   /**
276    * Determines if a transition from state to state exists.
277    *
278    * @param string $from_state_id
279    *   The state ID to transition from.
280    * @param string $to_state_id
281    *   The state ID to transition to.
282    *
283    * @return bool
284    *   TRUE if the transition exists, FALSE if not.
285    */
286   public function hasTransitionFromStateToState($from_state_id, $to_state_id);
287
288   /**
289    * Sets a transition's label.
290    *
291    * @param string $transition_id
292    *   The transition ID.
293    * @param string $label
294    *   The transition's label.
295    *
296    * @return $this
297    *
298    * @throws \InvalidArgumentException
299    *   Thrown if the transition does not exist.
300    */
301   public function setTransitionLabel($transition_id, $label);
302
303   /**
304    * Sets a transition's weight.
305    *
306    * @param string $transition_id
307    *   The transition ID.
308    * @param int $weight
309    *   The transition's weight.
310    *
311    * @return $this
312    *
313    * @throws \InvalidArgumentException
314    *   Thrown if the transition does not exist.
315    */
316   public function setTransitionWeight($transition_id, $weight);
317
318   /**
319    * Sets a transition's from states.
320    *
321    * @param string $transition_id
322    *   The transition ID.
323    * @param array $from_state_ids
324    *   The state IDs to transition from.
325    *
326    * @return $this
327    *
328    * @throws \InvalidArgumentException
329    *   Thrown if the transition does not exist or the states do not exist.
330    */
331   public function setTransitionFromStates($transition_id, array $from_state_ids);
332
333   /**
334    * Deletes a transition.
335    *
336    * @param string $transition_id
337    *   The transition ID.
338    *
339    * @return $this
340    *
341    * @throws \InvalidArgumentException
342    *   Thrown if the transition does not exist.
343    */
344   public function deleteTransition($transition_id);
345
346 }