You are here

public function WorkflowScheduledTransition::__construct in Workflow 7

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

Constructor No arguments passed, when loading from DB. All arguments must be passed, when creating an object programmatically. One argument $entity may be passed, only to directly call delete() afterwards.

Overrides WorkflowTransition::__construct

File

includes/Entity/WorkflowScheduledTransition.php, line 18
Contains workflow\includes\Entity\WorkflowScheduledTransition.

Class

WorkflowScheduledTransition

Code

public function __construct($entity_type = '', $entity = NULL, $field_name = '', $old_sid = 0, $new_sid = 0, $uid = 0, $stamp = 0, $comment = '') {
  $this->entity_type = !$entity_type ? $this->entity_type : $entity_type;
  $this->field_name = !$field_name ? $this->field_name : $field_name;
  $this->language = $this->language ? $this->language : 'und';
  $this->entity = $entity;

  // If constructor is called with new() and arguments.
  // Load the supplied entity.
  if ($entity && !$entity_type) {

    // Not all paramaters are passed programmatically.
    drupal_set_message('Wrong call to new WorkflowScheduledTransition()', 'error');
  }
  elseif ($entity) {

    // When supplying the $entity, the $entity_type musst be known, too.
    $this->entity_type = $entity_type;
    $this->entity_id = $entity_type == 'node' ? $entity->nid : entity_id($entity_type, $entity);
    $this->nid = $this->entity_id;
  }

  // If constructor is called with new() and arguments.
  if ($entity && $old_sid && $new_sid && $stamp) {
    $this->old_sid = $old_sid;
    $this->sid = $new_sid;
    $this->uid = $uid;
    $this->scheduled = $stamp;
    $this->comment = $comment;
  }
  elseif ($old_sid || $new_sid || $stamp) {

    // Not all paramaters are passed programmatically.
    drupal_set_message('Wrong call to new WorkflowScheduledTransition()', 'error');
  }

  // fill the 'new' fields correctly. @todo: rename these fields in db table.
  $this->entity_id = $this->nid;
  $this->new_sid = $this->sid;
}