You are here

public function WorkflowNodeGivenStateAction::execute in Workflow 8

Executes the plugin.

Overrides ExecutableInterface::execute

File

src/Plugin/Action/WorkflowNodeGivenStateAction.php, line 41

Class

WorkflowNodeGivenStateAction
Sets an entity to a new, given state.

Namespace

Drupal\workflow\Plugin\Action

Code

public function execute($object = NULL) {

  /*
   * D7: As advanced action with Trigger 'node':
   * - $entity is empty;
   * - $context['group'] = 'node'
   * - $context['hook'] = 'node_insert / _update / _delete'
   * - $context['node'] = (Object) stdClass
   * - $context['entity_type'] = NULL
   *
   * D7: As advanced action with Trigger 'taxonomy':
   * - $entity is (Object) stdClass;
   * - $context['type'] = 'entity'
   * - $context['group'] = 'taxonomy'
   * - $context['hook'] = 'taxonomy_term_insert / _update / _delete'
   * - $context['node'] = (Object) stdClass
   * - $context['entity_type'] = NULL
   *
   * D7: As advanced action with Trigger 'workflow API':
   * ...
   *
   * D7: As VBO action:
   * - $entity is (Object) stdClass;
   * - $context['type'] = NULL
   * - $context['group'] = NULL
   * - $context['hook'] = NULL
   * - $context['node'] = (Object) stdClass
   * - $context['entity_type'] = 'node'
   */
  if (!($transition = $this
    ->getTransitionForExecution($object))) {
    $this
      ->messenger()
      ->addStatus('The entity is not valid for this action.');
    return;
  }

  // Fire the transition.
  workflow_execute_transition($transition, $force = FALSE);
}