WorkflowTypeInterface.php 4.74 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
<?php

namespace Drupal\workflows;

use Drupal\Component\Plugin\ConfigurablePluginInterface;
use Drupal\Component\Plugin\DerivativeInspectionInterface;
use Drupal\Component\Plugin\PluginInspectionInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Session\AccountInterface;

/**
 * An interface for Workflow type plugins.
 *
 * @internal
 *   The workflow system is currently experimental and should only be leveraged
 *   by experimental modules and development releases of contributed modules.
 */
interface WorkflowTypeInterface extends PluginInspectionInterface, DerivativeInspectionInterface, ConfigurablePluginInterface {

20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
  /**
   * Initializes a workflow.
   *
   * Used to create required states and default transitions.
   *
   * @param \Drupal\workflows\WorkflowInterface $workflow
   *   The workflow to initialize.
   *
   * @return \Drupal\workflows\WorkflowInterface $workflow
   *   The initialized workflow.
   *
   * @see \Drupal\workflows\Form\WorkflowAddForm::save()
   */
  public function initializeWorkflow(WorkflowInterface $workflow);

35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
  /**
   * Gets the label for the workflow type.
   *
   * @return string
   *   The workflow type label.
   */
  public function label();

  /**
   * Performs access checks.
   *
   * @param \Drupal\workflows\WorkflowInterface $entity
   *   The workflow entity for which to check access.
   * @param string $operation
   *   The entity operation. Usually one of 'view', 'view label', 'update' or
   *   'delete'.
   * @param \Drupal\Core\Session\AccountInterface $account
   *   The user for which to check access.
   *
   * @return \Drupal\Core\Access\AccessResultInterface
   *   The access result.
   */
  public function checkWorkflowAccess(WorkflowInterface $entity, $operation, AccountInterface $account);

  /**
   * Decorates states so the WorkflowType can add additional information.
   *
   * @param \Drupal\workflows\StateInterface $state
   *   The state object to decorate.
   *
   * @return \Drupal\workflows\StateInterface $state
   *   The decorated state object.
   */
  public function decorateState(StateInterface $state);

  /**
   * React to the removal of a state from a workflow.
   *
   * @param string $state_id
   *   The state ID of the state that is being removed.
   */
  public function deleteState($state_id);

  /**
   * Decorates transitions so the WorkflowType can add additional information.
   * @param \Drupal\workflows\TransitionInterface $transition
   *   The transition object to decorate.
   *
   * @return \Drupal\workflows\TransitionInterface $transition
   *   The decorated transition object.
   */
  public function decorateTransition(TransitionInterface $transition);

  /**
   * React to the removal of a transition from a workflow.
   *
   * @param string $transition_id
   *   The transition ID of the transition that is being removed.
   */
  public function deleteTransition($transition_id);

  /**
   * Builds a form to be added to the Workflow state edit form.
   *
   * @param \Drupal\Core\Form\FormStateInterface $form_state
   *   The form state.
   * @param \Drupal\workflows\WorkflowInterface $workflow
   *   The workflow the state is attached to.
   * @param \Drupal\workflows\StateInterface|null $state
   *   The workflow state being edited. If NULL, a new state is being added.
   *
   * @return array
   *   Form elements to add to a workflow state form for customisations to the
   *   workflow.
   *
   * @see \Drupal\workflows\Form\WorkflowStateAddForm::form()
   * @see \Drupal\workflows\Form\WorkflowStateEditForm::form()
   */
  public function buildStateConfigurationForm(FormStateInterface $form_state, WorkflowInterface $workflow, StateInterface $state = NULL);

  /**
   * Builds a form to be added to the Workflow transition edit form.
   *
   * @param \Drupal\Core\Form\FormStateInterface $form_state
   *   The form state.
   * @param \Drupal\workflows\WorkflowInterface $workflow
   *   The workflow the state is attached to.
   * @param \Drupal\workflows\TransitionInterface|null $transition
   *   The workflow transition being edited. If NULL, a new transition is being
   *   added.
   *
   * @return array
   *   Form elements to add to a workflow transition form for customisations to
   *   the workflow.
   *
   * @see \Drupal\workflows\Form\WorkflowTransitionAddForm::form()
   * @see \Drupal\workflows\Form\WorkflowTransitionEditForm::form()
   */
  public function buildTransitionConfigurationForm(FormStateInterface $form_state, WorkflowInterface $workflow, TransitionInterface $transition = NULL);

135 136 137 138 139 140 141 142 143 144 145 146
  /**
   * Gets the required states of workflow type.
   *
   * This are usually configured in the workflow type annotation.
   *
   * @return array[]
   *   The required states.
   *
   * @see \Drupal\workflows\Annotation\WorkflowType
   */
  public function getRequiredStates();

147
}