WorkflowTypeInterface.php 9.2 KB

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