3 namespace Drupal\workflows;
5 use Drupal\Component\Plugin\ConfigurablePluginInterface;
6 use Drupal\Component\Plugin\DerivativeInspectionInterface;
7 use Drupal\Core\Plugin\PluginWithFormsInterface;
10 * An interface for Workflow type plugins.
12 interface WorkflowTypeInterface extends PluginWithFormsInterface, DerivativeInspectionInterface, ConfigurablePluginInterface {
15 * The key of the global workflow plugin form.
17 const PLUGIN_FORM_KEY = 'configure';
20 * Gets the label for the workflow type.
23 * The workflow type label.
25 public function label();
28 * Determines if the workflow is being has data associated with it.
31 * Marked as internal until it's validated this should form part of the
32 * public API in https://www.drupal.org/node/2897148.
34 * @param \Drupal\workflows\WorkflowInterface $workflow
35 * The workflow to check.
38 * TRUE if the workflow is being used, FALSE if not.
40 public function workflowHasData(WorkflowInterface $workflow);
43 * Determines if the workflow state has data associated with it.
46 * Marked as internal until it's validated this should form part of the
47 * public API in https://www.drupal.org/node/2897148.
49 * @param \Drupal\workflows\WorkflowInterface $workflow
50 * The workflow to check.
51 * @param \Drupal\workflows\StateInterface $state
52 * The workflow state to check.
55 * TRUE if the workflow state is being used, FALSE if not.
57 public function workflowStateHasData(WorkflowInterface $workflow, StateInterface $state);
60 * Gets the initial state for the workflow.
62 * @return \Drupal\workflows\StateInterface
65 public function getInitialState();
68 * Gets the required states of workflow type.
70 * This is usually specified in the workflow type annotation.
73 * The required states.
75 * @see \Drupal\workflows\Annotation\WorkflowType
77 public function getRequiredStates();
80 * Informs the plugin that a dependency of the workflow will be deleted.
82 * @param array $dependencies
83 * An array of dependencies that will be deleted keyed by dependency type.
86 * TRUE if the workflow settings have been changed, FALSE if not.
88 * @see \Drupal\Core\Config\ConfigEntityInterface::onDependencyRemoval()
90 * @todo https://www.drupal.org/node/2579743 make part of a generic interface.
92 public function onDependencyRemoval(array $dependencies);
95 * Adds a state to the workflow.
97 * @param string $state_id
99 * @param string $label
104 * @throws \InvalidArgumentException
105 * Thrown if a state already exists or state ID is invalid.
107 public function addState($state_id, $label);
110 * Determines if the workflow has a state with the provided ID.
112 * @param string $state_id
116 * TRUE if the workflow has a state with the provided ID, FALSE if not.
118 public function hasState($state_id);
121 * Gets state objects for the provided state IDs.
123 * @param string[] $state_ids
124 * A list of state IDs to get. If NULL then all states will be returned.
126 * @return \Drupal\workflows\StateInterface[]
127 * An array of workflow states, keyed by state IDs.
129 * @throws \InvalidArgumentException
130 * Thrown if $state_ids contains a state ID that does not exist.
132 public function getStates($state_ids = NULL);
135 * Gets a workflow state.
137 * @param string $state_id
140 * @return \Drupal\workflows\StateInterface
141 * The workflow state.
143 * @throws \InvalidArgumentException
144 * Thrown if $state_id does not exist.
146 public function getState($state_id);
149 * Sets a state's label.
151 * @param string $state_id
152 * The state ID to set the label for.
153 * @param string $label
158 public function setStateLabel($state_id, $label);
161 * Sets a state's weight value.
163 * @param string $state_id
164 * The state ID to set the weight for.
166 * The state's weight.
170 public function setStateWeight($state_id, $weight);
173 * Deletes a state from the workflow.
175 * @param string $state_id
176 * The state ID to delete.
178 * @return \Drupal\workflows\WorkflowTypeInterface
179 * The workflow type plugin.
181 * @throws \InvalidArgumentException
182 * Thrown if $state_id does not exist.
184 public function deleteState($state_id);
187 * Adds a transition to the workflow.
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.
200 * @throws \InvalidArgumentException
201 * Thrown if either state does not exist.
203 public function addTransition($id, $label, array $from_state_ids, $to_state_id);
206 * Gets a transition object for the provided transition ID.
208 * @param string $transition_id
211 * @return \Drupal\workflows\TransitionInterface
214 * @throws \InvalidArgumentException
215 * Thrown if $transition_id does not exist.
217 public function getTransition($transition_id);
220 * Determines if a transition exists.
222 * @param string $transition_id
226 * TRUE if the transition exists, FALSE if not.
228 public function hasTransition($transition_id);
231 * Gets transition objects for the provided transition IDs.
233 * @param string[] $transition_ids
234 * A list of transition IDs to get. If NULL then all transitions will be
237 * @return \Drupal\workflows\TransitionInterface[]
238 * An array of transition objects.
240 * @throws \InvalidArgumentException
241 * Thrown if $transition_ids contains a transition ID that does not exist.
243 public function getTransitions(array $transition_ids = NULL);
246 * Gets the transition IDs for a state for the provided direction.
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.
256 * The transition IDs for a state for the provided direction.
258 * @see \Drupal\workflows\TransitionInterface::DIRECTION_FROM
259 * @see \Drupal\workflows\TransitionInterface::DIRECTION_TO
261 public function getTransitionsForState($state_id, $direction = TransitionInterface::DIRECTION_FROM);
264 * Gets a transition from state to state.
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.
271 * @return \Drupal\workflows\TransitionInterface
274 * @throws \InvalidArgumentException
275 * Thrown if the transition does not exist.
277 public function getTransitionFromStateToState($from_state_id, $to_state_id);
280 * Determines if a transition from state to state exists.
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.
288 * TRUE if the transition exists, FALSE if not.
290 public function hasTransitionFromStateToState($from_state_id, $to_state_id);
293 * Sets a transition's label.
295 * @param string $transition_id
297 * @param string $label
298 * The transition's label.
302 * @throws \InvalidArgumentException
303 * Thrown if the transition does not exist.
305 public function setTransitionLabel($transition_id, $label);
308 * Sets a transition's weight.
310 * @param string $transition_id
313 * The transition's weight.
317 * @throws \InvalidArgumentException
318 * Thrown if the transition does not exist.
320 public function setTransitionWeight($transition_id, $weight);
323 * Sets a transition's from states.
325 * @param string $transition_id
327 * @param array $from_state_ids
328 * The state IDs to transition from.
332 * @throws \InvalidArgumentException
333 * Thrown if the transition does not exist or the states do not exist.
335 public function setTransitionFromStates($transition_id, array $from_state_ids);
338 * Deletes a transition.
340 * @param string $transition_id
345 * @throws \InvalidArgumentException
346 * Thrown if the transition does not exist.
348 public function deleteTransition($transition_id);