3 namespace Drupal\workflows;
5 use Drupal\Core\Config\Entity\ConfigEntityInterface;
8 * Provides an interface for defining workflow entities.
11 * The workflow system is currently experimental and should only be leveraged
12 * by experimental modules and development releases of contributed modules.
14 interface WorkflowInterface extends ConfigEntityInterface {
17 * Adds a state to the workflow.
19 * @param string $state_id
21 * @param string $label
24 * @return \Drupal\workflows\WorkflowInterface
25 * The workflow entity.
27 public function addState($state_id, $label);
30 * Determines if the workflow has a state with the provided ID.
32 * @param string $state_id
36 * TRUE if the workflow has a state with the provided ID, FALSE if not.
38 public function hasState($state_id);
41 * Gets state objects for the provided state IDs.
43 * @param string[] $state_ids
44 * A list of state IDs to get. If NULL then all states will be returned.
46 * @return \Drupal\workflows\StateInterface[]
47 * An array of workflow states.
49 * @throws \InvalidArgumentException
50 * Thrown if $state_ids contains a state ID that does not exist.
52 public function getStates($state_ids = NULL);
55 * Gets a workflow state.
57 * @param string $state_id
60 * @return \Drupal\workflows\StateInterface
63 * @throws \InvalidArgumentException
64 * Thrown if $state_id does not exist.
66 public function getState($state_id);
69 * Sets a state's label.
71 * @param string $state_id
72 * The state ID to set the label for.
73 * @param string $label
76 * @return \Drupal\workflows\WorkflowInterface
77 * The workflow entity.
79 public function setStateLabel($state_id, $label);
82 * Sets a state's weight value.
84 * @param string $state_id
85 * The state ID to set the weight for.
89 * @return \Drupal\workflows\WorkflowInterface
90 * The workflow entity.
92 public function setStateWeight($state_id, $weight);
95 * Deletes a state from the workflow.
97 * @param string $state_id
98 * The state ID to delete.
100 * @return \Drupal\workflows\WorkflowInterface
101 * The workflow entity.
103 * @throws \InvalidArgumentException
104 * Thrown if $state_id does not exist.
106 public function deleteState($state_id);
109 * Adds a transition to the workflow.
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.
120 * @return \Drupal\workflows\WorkflowInterface
121 * The workflow entity.
123 * @throws \InvalidArgumentException
124 * Thrown if either state does not exist.
126 public function addTransition($id, $label, array $from_state_ids, $to_state_id);
129 * Gets a transition object for the provided transition ID.
131 * @param string $transition_id
134 * @return \Drupal\workflows\TransitionInterface
137 * @throws \InvalidArgumentException
138 * Thrown if $transition_id does not exist.
140 public function getTransition($transition_id);
143 * Determines if a transition exists.
145 * @param string $transition_id
149 * TRUE if the transition exists, FALSE if not.
151 public function hasTransition($transition_id);
154 * Gets transition objects for the provided transition IDs.
156 * @param string[] $transition_ids
157 * A list of transition IDs to get. If NULL then all transitions will be
160 * @return \Drupal\workflows\TransitionInterface[]
161 * An array of transition objects.
163 * @throws \InvalidArgumentException
164 * Thrown if $transition_ids contains a transition ID that does not exist.
166 public function getTransitions(array $transition_ids = NULL);
169 * Gets the transition IDs for a state for the provided direction.
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'.
178 * The transition IDs for a state for the provided direction.
180 public function getTransitionsForState($state_id, $direction = 'from');
183 * Gets a transition from state to state.
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.
190 * @return \Drupal\workflows\TransitionInterface
193 * @throws \InvalidArgumentException
194 * Thrown if the transition does not exist.
196 public function getTransitionFromStateToState($from_state_id, $to_state_id);
199 * Determines if a transition from state to state exists.
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.
207 * TRUE if the transition exists, FALSE if not.
209 public function hasTransitionFromStateToState($from_state_id, $to_state_id);
212 * Sets a transition's label.
214 * @param string $transition_id
216 * @param string $label
217 * The transition's label.
219 * @return \Drupal\workflows\WorkflowInterface
220 * The workflow entity.
222 * @throws \InvalidArgumentException
223 * Thrown if the transition does not exist.
225 public function setTransitionLabel($transition_id, $label);
228 * Sets a transition's weight.
230 * @param string $transition_id
233 * The transition's weight.
235 * @return \Drupal\workflows\WorkflowInterface
236 * The workflow entity.
238 * @throws \InvalidArgumentException
239 * Thrown if the transition does not exist.
241 public function setTransitionWeight($transition_id, $weight);
244 * Sets a transition's from states.
246 * @param string $transition_id
248 * @param array $from_state_ids
249 * The state IDs to transition from.
251 * @return \Drupal\workflows\WorkflowInterface
252 * The workflow entity.
254 * @throws \InvalidArgumentException
255 * Thrown if the transition does not exist or the states do not exist.
257 public function setTransitionFromStates($transition_id, array $from_state_ids);
260 * Deletes a transition.
262 * @param string $transition_id
265 * @return \Drupal\workflows\WorkflowInterface
266 * The workflow entity.
268 * @throws \InvalidArgumentException
269 * Thrown if the transition does not exist.
271 public function deleteTransition($transition_id);
274 * Gets the workflow type plugin.
276 * @return \Drupal\workflows\WorkflowTypeInterface
277 * The workflow type plugin.
279 public function getTypePlugin();