You are here

public function WorkflowState::__construct in Workflow 7.2

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

Constructor.

Parameters

array $values:

string $entityType:

Overrides Entity::__construct

File

includes/Entity/WorkflowState.php, line 33
Contains workflow\includes\Entity\WorkflowState. Contains workflow\includes\Entity\WorkflowStateController.

Class

WorkflowState
Class WorkflowState

Code

public function __construct(array $values = array(), $entityType = 'WorkflowState') {

  // Please be aware that $entity_type and $entityType are different things!
  // Keep official name and external name equal. Both are required.
  // @todo: still needed? test import, manual creation, programmatic creation, etc.
  if (!isset($values['state']) && isset($values['name'])) {
    $values['state'] = $values['name'];
  }

  // Set default values for '(creation)' state.
  if (!empty($values['is_new']) && $values['name'] == WORKFLOW_CREATION_STATE_NAME) {
    $values['sysid'] = WORKFLOW_CREATION;
    $values['weight'] = WORKFLOW_CREATION_DEFAULT_WEIGHT;
    $values['name'] = '(creation)';

    // machine_name;
  }
  parent::__construct($values, $entityType);
  if (empty($values)) {

    // Automatic constructor when casting an array or object.
    // Add pre-existing states to cache (not new/temp ones).
    if (!isset(self::$states[$this->sid])) {
      self::$states[$this->sid] = $this;
    }
  }
}