0cb47a49044aa5d139007d3bb5eeb8ec8643fd06
[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, keyed by state IDs.
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
252    *   TransitionInterface::DIRECTION_FROM. Possible values are:
253    *   TransitionInterface::DIRECTION_FROM or TransitionInterface::DIRECTION_TO.
254    *
255    * @return array
256    *   The transition IDs for a state for the provided direction.
257    *
258    * @see \Drupal\workflows\TransitionInterface::DIRECTION_FROM
259    * @see \Drupal\workflows\TransitionInterface::DIRECTION_TO
260    */
261   public function getTransitionsForState($state_id, $direction = TransitionInterface::DIRECTION_FROM);
262
263   /**
264    * Gets a transition from state to state.
265    *
266    * @param string $from_state_id
267    *   The state ID to transition from.
268    * @param string $to_state_id
269    *   The state ID to transition to.
270    *
271    * @return \Drupal\workflows\TransitionInterface
272    *   The transitions.
273    *
274    * @throws \InvalidArgumentException
275    *   Thrown if the transition does not exist.
276    */
277   public function getTransitionFromStateToState($from_state_id, $to_state_id);
278
279   /**
280    * Determines if a transition from state to state exists.
281    *
282    * @param string $from_state_id
283    *   The state ID to transition from.
284    * @param string $to_state_id
285    *   The state ID to transition to.
286    *
287    * @return bool
288    *   TRUE if the transition exists, FALSE if not.
289    */
290   public function hasTransitionFromStateToState($from_state_id, $to_state_id);
291
292   /**
293    * Sets a transition's label.
294    *
295    * @param string $transition_id
296    *   The transition ID.
297    * @param string $label
298    *   The transition's label.
299    *
300    * @return $this
301    *
302    * @throws \InvalidArgumentException
303    *   Thrown if the transition does not exist.
304    */
305   public function setTransitionLabel($transition_id, $label);
306
307   /**
308    * Sets a transition's weight.
309    *
310    * @param string $transition_id
311    *   The transition ID.
312    * @param int $weight
313    *   The transition's weight.
314    *
315    * @return $this
316    *
317    * @throws \InvalidArgumentException
318    *   Thrown if the transition does not exist.
319    */
320   public function setTransitionWeight($transition_id, $weight);
321
322   /**
323    * Sets a transition's from states.
324    *
325    * @param string $transition_id
326    *   The transition ID.
327    * @param array $from_state_ids
328    *   The state IDs to transition from.
329    *
330    * @return $this
331    *
332    * @throws \InvalidArgumentException
333    *   Thrown if the transition does not exist or the states do not exist.
334    */
335   public function setTransitionFromStates($transition_id, array $from_state_ids);
336
337   /**
338    * Deletes a transition.
339    *
340    * @param string $transition_id
341    *   The transition ID.
342    *
343    * @return $this
344    *
345    * @throws \InvalidArgumentException
346    *   Thrown if the transition does not exist.
347    */
348   public function deleteTransition($transition_id);
349
350 }