You are here

function hook_workflow in Workflow 8

Same name and namespace in other branches
  1. 7.2 workflow.api.php \hook_workflow()
  2. 7 workflow.api.php \hook_workflow()
  3. 7 workflow_admin_ui/workflow_admin_ui.api.php \hook_workflow()

Implements hook_workflow().

NOTE: This hook may reside in the implementing module or in a module.workflow.inc file.

Parameters

string $op: The current workflow operation. E.g., 'transition pre', 'transition post'.

\Drupal\workflow\Entity\WorkflowTransitionInterface $transition: The transition, that contains all of the above.

\Drupal\user\UserInterface $user:

Return value

bool|void The return value, depending on $op.

1 call to hook_workflow()
workflow_devel_workflow in modules/workflow_devel/workflow_devel.module
@inheritdoc
2 functions implement hook_workflow()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

workflow_devel_workflow in modules/workflow_devel/workflow_devel.module
@inheritdoc
workflow_url_get_workflow in ./workflow.module
Helper function to determine Workflow from Workflow UI URL.
3 invocations of hook_workflow()
WorkflowAccessControlHandler::access in src/WorkflowAccessControlHandler.php
Checks access to an operation on a given entity or entity translation.
WorkflowTransition::execute in src/Entity/WorkflowTransition.php
Execute a transition (change state of an entity).
WorkflowTransition::post_execute in src/Entity/WorkflowTransition.php
Invokes 'transition post'.

File

./workflow.api.php, line 96
Hooks provided by the workflow module.

Code

function hook_workflow($op, WorkflowTransitionInterface $transition, UserInterface $user) {
  switch ($op) {
    case 'transition permitted':

      // As of version 8.x-1.x, this operation is never called to check if transition is permitted.
      // This was called in the following situations:
      // case 1. when building a workflow widget with list of available transitions;
      // case 2. when executing a transition, just before the 'transition pre';
      // case 3. when showing a 'revert state' link in a Views display.
      // Your module's implementation may return FALSE here and disallow
      // the execution, or avoid the presentation of the new State.
      // This may be user-dependent.
      // As of version 8.x-1.x:
      // case 1: use hook_workflow_permitted_state_transitions_alter(),
      // case 2: use the 'transition pre' operation,
      // case 3: use the 'transition pre' operation.
      return TRUE;
    case 'transition revert':

      // Hook is called when showing the Transition Revert form.
      // Implement this hook if you need to control this.
      // If you return FALSE here, you will veto the transition.
      // workflow_debug(__FILE__, __FUNCTION__, __LINE__, $op, '');
      return TRUE;
    case 'transition pre':

      // The workflow module does nothing during this operation.
      // Implement this hook if you need to change/do something BEFORE anything
      // is saved to the database.
      // If you return FALSE here, you will veto the transition.
      // workflow_debug(__FILE__, __FUNCTION__, __LINE__, $op, '');
      return TRUE;
    case 'transition post':

      // In D7, this is called by Workflow Node during update of the state, directly
      // after updating the Workflow. Workflow Field does not call this,
      // since you can call a hook_entity_* event after saving the entity.
      // @see https://api.drupal.org/api/drupal/includes%21module.inc/group/hooks/7
      // workflow_debug(__FILE__, __FUNCTION__, __LINE__, $op, '');
      return TRUE;
    case 'transition delete':
    case 'state delete':
    case 'workflow delete':

      // These hooks are removed in D8, in favour of the core hooks:
      // - workflow_entity_predelete(EntityInterface $entity)
      // - workflow_entity_delete(EntityInterface $entity)
      // See examples at the bottom of this file.
      return TRUE;
  }
  return TRUE;
}