WorkflowInterface.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. <?php
  2. /**
  3. * @file
  4. * Contains Drupal\workflow\Entity\WorkflowInterface.
  5. */
  6. // D8: namespace Drupal\workflow\Entity;
  7. // D8: use Drupal\Core\Config\Entity\ConfigEntityBase;
  8. // D8: use Drupal\Core\Session\AccountInterface;
  9. /**
  10. * Defines a common interface for Workflow*Transition* objects.
  11. *
  12. * @see \Drupal\workflow\Entity\WorkflowConfigTransition
  13. * @see \Drupal\workflow\Entity\WorkflowTransition
  14. * @see \Drupal\workflow\Entity\WorkflowScheduledTransition
  15. */
  16. interface WorkflowInterface {
  17. /**
  18. * Retrieves the entity manager service.
  19. *
  20. * @return \Drupal\workflow\Entity\WorkflowManagerInterface
  21. * The entity manager service.
  22. */
  23. //D8: public static function workflowManager();
  24. /**
  25. * Returns the workflow id.
  26. *
  27. * @return string
  28. * $wid
  29. */
  30. public function getWorkflowId();
  31. /**
  32. * Validate the workflow. Generate a message if not correct.
  33. *
  34. * This function is used on the settings page of:
  35. * - Workflow field: WorkflowItem->settingsForm()
  36. *
  37. * @return bool
  38. * $is_valid
  39. */
  40. public function isValid();
  41. /**
  42. * Returns if the Workflow may be deleted.
  43. *
  44. * @return bool $is_deletable
  45. * TRUE if a Workflow may safely be deleted.
  46. */
  47. public function isDeletable();
  48. /**
  49. * Create a new state for this workflow.
  50. *
  51. * @param string $name
  52. * The untranslated human readable label of the state.
  53. * @param bool $save
  54. * Indicator if the new state must be saved. Normally, the new State is
  55. * saved directly in the database. This is because you can use States only
  56. * with Transitions, and they rely on State IDs which are generated
  57. * magically when saving the State. But you may need a temporary state.
  58. * @return \Drupal\workflow\Entity\WorkflowState
  59. * The new state.
  60. */
  61. public function createState($sid, $save = TRUE);
  62. /**
  63. * Gets the initial state for a newly created entity.
  64. */
  65. public function getCreationState();
  66. /**
  67. * Gets the ID of the initial state for a newly created entity.
  68. */
  69. public function getCreationSid();
  70. /**
  71. * Gets the first valid state ID, after the creation state.
  72. *
  73. * Uses WorkflowState::getOptions(), because this does an access check.
  74. * The first State ID is user-dependent!
  75. */
  76. public function getFirstSid($entity_type, $entity, $field_name, $user, $force);
  77. /**
  78. * Returns the next state for the current state.
  79. * Is used in VBO Bulk actions.
  80. *
  81. * @param string $entity_type
  82. * The type of the entity at hand.
  83. * @param object $entity
  84. * The entity at hand. May be NULL (E.g., on a Field settings page).
  85. * @param $field_name
  86. * @param $user
  87. * @param bool $force
  88. *
  89. * @return array
  90. * An array of sid=>label pairs.
  91. * If $this->sid is set, returns the allowed transitions from this state.
  92. * If $this->sid is 0 or FALSE, then labels of ALL states of the State's
  93. * Workflow are returned.
  94. *
  95. */
  96. public function getNextSid($entity_type, $entity, $field_name, $user, $force = FALSE);
  97. /**
  98. * Gets all states for a given workflow.
  99. *
  100. * @param mixed $all
  101. * Indicates to which states to return.
  102. * - TRUE = all, including Creation and Inactive;
  103. * - FALSE = only Active states, not Creation;
  104. * - 'CREATION' = only Active states, including Creation.
  105. *
  106. * @return WorkflowState[]
  107. * An array of WorkflowState objects.
  108. */
  109. public function getStates($all = FALSE, $reset = FALSE);
  110. /**
  111. * Gets a state for a given workflow.
  112. *
  113. * @param mixed $key
  114. * A state ID or state Name.
  115. *
  116. * @return WorkflowState
  117. * A WorkflowState object.
  118. */
  119. public function getState($sid);
  120. /**
  121. * Creates a Transition for this workflow.
  122. *
  123. * @param string $from_sid
  124. * @param string $to_sid
  125. * @param array $values
  126. *
  127. * @return mixed|null|static
  128. */
  129. public function createTransition($from_sid, $to_sid, $values = array());
  130. /**
  131. * Sorts all Transitions for this workflow, according to State weight.
  132. *
  133. * This is only needed for the Admin UI.
  134. */
  135. public function sortTransitions();
  136. /**
  137. * Loads all allowed ConfigTransitions for this workflow.
  138. *
  139. * @param array|bool $tids
  140. * Array of Transitions IDs. If FALSE, show all transitions.
  141. * @param array $conditions
  142. * $conditions['sid'] : if provided, a 'from' State ID.
  143. * $conditions['target_sid'] : if provided, a 'to' state ID.
  144. * $conditions['roles'] : if provided, an array of roles, or 'ALL'.
  145. * @param bool $reset
  146. * Indicator to reset the cache.
  147. *
  148. * @return \Drupal\workflow\Entity\WorkflowConfigTransition[]
  149. */
  150. public function getTransitions($tids = FALSE, array $conditions = array(), $reset = FALSE);
  151. public function getTransitionsByTid($tid);
  152. /**
  153. *
  154. * Get a specific transition.
  155. *
  156. * @param string $from_sid
  157. * @param string $to_sid
  158. *
  159. * @return WorkflowConfigTransition[]
  160. */
  161. //D8: public function getTransitionsByStateId($from_sid, $to_sid);
  162. }