d156918a6f18f7b83d9d3dd6d03ad33271535632
[yaffs-website] / web / core / modules / workflows / src / WorkflowInterface.php
1 <?php
2
3 namespace Drupal\workflows;
4
5 use Drupal\Core\Config\Entity\ConfigEntityInterface;
6
7 /**
8  * Provides an interface for defining workflow entities.
9  *
10  * @internal
11  *   The workflow system is currently experimental and should only be leveraged
12  *   by experimental modules and development releases of contributed modules.
13  */
14 interface WorkflowInterface extends ConfigEntityInterface {
15
16   /**
17    * Adds a state to the workflow.
18    *
19    * @param string $state_id
20    *   The state's ID.
21    * @param string $label
22    *   The state's label.
23    *
24    * @return \Drupal\workflows\WorkflowInterface
25    *   The workflow entity.
26    */
27   public function addState($state_id, $label);
28
29   /**
30    * Determines if the workflow has a state with the provided ID.
31    *
32    * @param string $state_id
33    *   The state's ID.
34    *
35    * @return bool
36    *   TRUE if the workflow has a state with the provided ID, FALSE if not.
37    */
38   public function hasState($state_id);
39
40   /**
41    * Gets state objects for the provided state IDs.
42    *
43    * @param string[] $state_ids
44    *   A list of state IDs to get. If NULL then all states will be returned.
45    *
46    * @return \Drupal\workflows\StateInterface[]
47    *   An array of workflow states.
48    *
49    * @throws \InvalidArgumentException
50    *   Thrown if $state_ids contains a state ID that does not exist.
51    */
52   public function getStates($state_ids = NULL);
53
54   /**
55    * Gets a workflow state.
56    *
57    * @param string $state_id
58    *   The state's ID.
59    *
60    * @return \Drupal\workflows\StateInterface
61    *   The workflow state.
62    *
63    * @throws \InvalidArgumentException
64    *   Thrown if $state_id does not exist.
65    */
66   public function getState($state_id);
67
68   /**
69    * Sets a state's label.
70    *
71    * @param string $state_id
72    *   The state ID to set the label for.
73    * @param string $label
74    *   The state's label.
75    *
76    * @return \Drupal\workflows\WorkflowInterface
77    *   The workflow entity.
78    */
79   public function setStateLabel($state_id, $label);
80
81   /**
82    * Sets a state's weight value.
83    *
84    * @param string $state_id
85    *   The state ID to set the weight for.
86    * @param int $weight
87    *   The state's weight.
88    *
89    * @return \Drupal\workflows\WorkflowInterface
90    *   The workflow entity.
91    */
92   public function setStateWeight($state_id, $weight);
93
94   /**
95    * Deletes a state from the workflow.
96    *
97    * @param string $state_id
98    *   The state ID to delete.
99    *
100    * @return \Drupal\workflows\WorkflowInterface
101    *   The workflow entity.
102    *
103    * @throws \InvalidArgumentException
104    *   Thrown if $state_id does not exist.
105    */
106   public function deleteState($state_id);
107
108   /**
109    * Adds a transition to the workflow.
110    *
111    * @param string $id
112    *   The transition ID.
113    * @param string $label
114    *   The transition's label.
115    * @param array $from_state_ids
116    *   The state IDs to transition from.
117    * @param string $to_state_id
118    *   The state ID to transition to.
119    *
120    * @return \Drupal\workflows\WorkflowInterface
121    *   The workflow entity.
122    *
123    * @throws \InvalidArgumentException
124    *   Thrown if either state does not exist.
125    */
126   public function addTransition($id, $label, array $from_state_ids, $to_state_id);
127
128   /**
129    * Gets a transition object for the provided transition ID.
130    *
131    * @param string $transition_id
132    *   A transition ID.
133    *
134    * @return \Drupal\workflows\TransitionInterface
135    *   The transition.
136    *
137    * @throws \InvalidArgumentException
138    *   Thrown if $transition_id does not exist.
139    */
140   public function getTransition($transition_id);
141
142   /**
143    * Determines if a transition exists.
144    *
145    * @param string $transition_id
146    *   The transition ID.
147    *
148    * @return bool
149    *   TRUE if the transition exists, FALSE if not.
150    */
151   public function hasTransition($transition_id);
152
153   /**
154    * Gets transition objects for the provided transition IDs.
155    *
156    * @param string[] $transition_ids
157    *   A list of transition IDs to get. If NULL then all transitions will be
158    *   returned.
159    *
160    * @return \Drupal\workflows\TransitionInterface[]
161    *   An array of transition objects.
162    *
163    * @throws \InvalidArgumentException
164    *   Thrown if $transition_ids contains a transition ID that does not exist.
165    */
166   public function getTransitions(array $transition_ids = NULL);
167
168   /**
169    * Gets the transition IDs for a state for the provided direction.
170    *
171    * @param $state_id
172    *   The state to get transitions for.
173    * @param string $direction
174    *   (optional) The direction of the transition. Defaults to 'from'. Possible
175    *   values are: 'from' and 'to'.
176    *
177    * @return array
178    *   The transition IDs for a state for the provided direction.
179    */
180   public function getTransitionsForState($state_id, $direction = 'from');
181
182   /**
183    * Gets a transition from state to state.
184    *
185    * @param string $from_state_id
186    *   The state ID to transition from.
187    * @param string $to_state_id
188    *   The state ID to transition to.
189    *
190    * @return \Drupal\workflows\TransitionInterface
191    *   The transitions.
192    *
193    * @throws \InvalidArgumentException
194    *   Thrown if the transition does not exist.
195    */
196   public function getTransitionFromStateToState($from_state_id, $to_state_id);
197
198   /**
199    * Determines if a transition from state to state exists.
200    *
201    * @param string $from_state_id
202    *   The state ID to transition from.
203    * @param string $to_state_id
204    *   The state ID to transition to.
205    *
206    * @return bool
207    *   TRUE if the transition exists, FALSE if not.
208    */
209   public function hasTransitionFromStateToState($from_state_id, $to_state_id);
210
211   /**
212    * Sets a transition's label.
213    *
214    * @param string $transition_id
215    *   The transition ID.
216    * @param string $label
217    *   The transition's label.
218    *
219    * @return \Drupal\workflows\WorkflowInterface
220    *   The workflow entity.
221    *
222    * @throws \InvalidArgumentException
223    *   Thrown if the transition does not exist.
224    */
225   public function setTransitionLabel($transition_id, $label);
226
227   /**
228    * Sets a transition's weight.
229    *
230    * @param string $transition_id
231    *   The transition ID.
232    * @param int $weight
233    *   The transition's weight.
234    *
235    * @return \Drupal\workflows\WorkflowInterface
236    *   The workflow entity.
237    *
238    * @throws \InvalidArgumentException
239    *   Thrown if the transition does not exist.
240    */
241   public function setTransitionWeight($transition_id, $weight);
242
243   /**
244    * Sets a transition's from states.
245    *
246    * @param string $transition_id
247    *   The transition ID.
248    * @param array $from_state_ids
249    *   The state IDs to transition from.
250    *
251    * @return \Drupal\workflows\WorkflowInterface
252    *   The workflow entity.
253    *
254    * @throws \InvalidArgumentException
255    *   Thrown if the transition does not exist or the states do not exist.
256    */
257   public function setTransitionFromStates($transition_id, array   $from_state_ids);
258
259   /**
260    * Deletes a transition.
261    *
262    * @param string $transition_id
263    *   The transition ID.
264    *
265    * @return \Drupal\workflows\WorkflowInterface
266    *   The workflow entity.
267    *
268    * @throws \InvalidArgumentException
269    *   Thrown if the transition does not exist.
270    */
271   public function deleteTransition($transition_id);
272
273   /**
274    * Gets the workflow type plugin.
275    *
276    * @return \Drupal\workflows\WorkflowTypeInterface
277    *   The workflow type plugin.
278    */
279   public function getTypePlugin();
280
281 }