You are here

public function WorkflowTransition::setEntity in Workflow 7

Same name and namespace in other branches
  1. 7.2 includes/Entity/WorkflowTransition.php \WorkflowTransition::setEntity()

File

includes/Entity/WorkflowTransition.php, line 270
Contains workflow\includes\Entity\WorkflowTransition.

Class

WorkflowTransition
Implements an actual Transition.

Code

public function setEntity($entity_type, $entity) {
  if (!is_object($entity)) {
    $entity_id = $entity;

    // Use node API or Entity API to load the object first.
    $entity = $entity_type == 'node' ? node_load($entity_id) : array_shift(entity_load($entity_type, array(
      $entity_id,
    )));
  }
  $this->entity = $entity;
  $this->entity_type = $entity_type;
  $this->entity_id = $entity_type == 'node' ? $entity->nid : entity_id($entity_type, $entity);
  $this->nid = $this->entity_id;
  return $this->entity;
}