PageRenderTime 43ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/web/core/modules/workflows/src/WorkflowTypeInterface.php

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