You are here

public function WorkflowConfigTransition::save in Workflow 8

Saves an entity permanently.

When saving existing entities, the entity is assumed to be complete, partial updates of entities are not supported.

Return value

int Either SAVED_NEW or SAVED_UPDATED, depending on the operation performed.

Throws

\Drupal\Core\Entity\EntityStorageException In case of failures an exception is thrown.

Overrides ConfigEntityBase::save

File

src/Entity/WorkflowConfigTransition.php, line 115

Class

WorkflowConfigTransition
Workflow configuration entity to persistently store configuration.

Namespace

Drupal\workflow\Entity

Code

public function save() {
  $workflow = $this
    ->getWorkflow();

  // To avoid double posting, check if this (new) transition already exist.
  if (empty($this
    ->id())) {
    if ($workflow) {
      $config_transitions = $workflow
        ->getTransitionsByStateId($this->from_sid, $this->to_sid);
      $config_transition = reset($config_transitions);
      if ($config_transition) {
        $this
          ->set('id', $config_transition
          ->id());
      }
    }
  }

  // Create the machine_name.
  // This can be used to rebuild/revert the Feature in a target system.
  if (empty($this
    ->id())) {
    $wid = $workflow
      ->id();
    $this
      ->set('id', implode('', [
      $wid,
      substr($this->from_sid, strlen($wid)),
      substr($this->to_sid, strlen($wid)),
    ]));
  }
  $status = parent::save();
  if ($status) {

    // Save in current workflow for the remainder of this page request.
    // Keep in sync with Workflow::getTransitions() !
    if ($workflow) {
      $workflow->transitions[$this
        ->id()] = $this;

      // $workflow->sortTransitions();
    }
  }
  return $status;
}