You are here

function workflow_execute_transition in Workflow 7.2

Same name and namespace in other branches
  1. 8 workflow.module \workflow_execute_transition()
  2. 5.2 workflow.module \workflow_execute_transition()
  3. 5 workflow.module \workflow_execute_transition()
  4. 6.2 workflow.module \workflow_execute_transition()
  5. 6 workflow.module \workflow_execute_transition()
  6. 7 workflow.module \workflow_execute_transition()

Executes a transition (change state of a node), from outside the node, e.g., workflow_cron().

Serves as a wrapper function to hide differences between Node API and Field API. Use workflow_execute_transition($transition) to start a State Change from outside an entity. Use $transition->execute() to start a State Change from within an enetity.

Parameters

string $entity_type: Entity type of target entity.

object $entity: Target entity.

string $field_name: A field name, used when changing a Workflow Field.

object $transition: A WorkflowTransition or WorkflowScheduledTransition.

bool $force: If set to TRUE, workflow permissions will be ignored.

Return value

int The new state ID.

8 calls to workflow_execute_transition()
workflownode_node_insert in workflow_node/workflownode.module
Implements hook_node_insert().
WorkflowState::deactivate in includes/Entity/WorkflowState.php
Deactivate a Workflow State, moving existing nodes to a given State.
workflow_cron in ./workflow.module
Implements hook_cron().
workflow_revert_form_submit in workflow_revert/workflow_revert.pages.inc
Submit callback function.
workflow_vbo_given_state_action in workflow_vbo/actions/given.action.inc
Implements a Drupal action. Move a node to a specified state in the workflow.

... See full list

File

./workflow.module, line 540
Support workflows made up of arbitrary states.

Code

function workflow_execute_transition($entity_type, $entity, $field_name, $transition, $force = FALSE) {

  // $todo D8: Remove first 3 parameters - they can be extracted from $transition.
  // Make sure $force is set in the transition, too.
  if ($force) {
    $transition
      ->force($force);
  }
  $force = $transition
    ->isForced();
  if ($field_name) {

    // @todo: use $new_sid = $transition->execute() without generating infinite loops.
    $langcode = $transition->language;

    // Do a separate update to update the field (Workflow Field API)
    // This will call hook_field_update() and WorkflowFieldDefaultWidget::submit().
    $entity->{$field_name}[$langcode][0]['transition'] = $transition;
    $entity->{$field_name}[$langcode][0]['value'] = $transition->new_sid;

    // Save only the field, not the complete entity.
    workflow_entity_field_save($entity_type, $entity, $field_name, $langcode, FALSE);
    $new_sid = workflow_node_current_state($entity, $entity_type, $field_name);
  }
  else {

    // For Node API, the node is not saved, since all fields are custom.
    // Force = TRUE for backwards compatibility with version 7.x-1.2
    $new_sid = $transition
      ->execute($force = TRUE);
  }
  return $new_sid;
}