You are here

public function WorkflowState::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

1 call to WorkflowState::save()
WorkflowState::deactivate in src/Entity/WorkflowState.php
Deactivate a Workflow State, moving existing content to a given State.

File

src/Entity/WorkflowState.php, line 156

Class

WorkflowState
Workflow configuration entity to persistently store configuration.

Namespace

Drupal\workflow\Entity

Code

public function save($create_creation_state = TRUE) {

  // Create the machine_name for new states.
  // N.B.: Keep machine_name in WorkflowState and ~ListBuilder aligned.
  $sid = $this
    ->id();
  $wid = $this
    ->getWorkflowId();
  $label = $this
    ->label();

  // Set the workflow-including machine_name.
  if ($sid == WORKFLOW_CREATION_STATE_NAME) {

    // Set the initial sid.
    $sid = implode('_', [
      $wid,
      $sid,
    ]);
    $this
      ->set('id', $sid);
  }
  elseif (empty($sid)) {
    if ($label) {
      $transliteration = \Drupal::service('transliteration');
      $value = $transliteration
        ->transliterate($label, LanguageInterface::LANGCODE_DEFAULT, '_');
      $value = strtolower($value);
      $value = preg_replace('/[^a-z0-9_]+/', '_', $value);
      $sid = implode('_', [
        $wid,
        $value,
      ]);
    }
    else {
      workflow_debug(__FILE__, __FUNCTION__, __LINE__);

      // @todo D8-port: still test this snippet.
      $sid = 'state_' . $this
        ->id();
      $sid = implode('_', [
        $wid,
        $sid,
      ]);
    }
    $this
      ->set('id', $sid);
  }
  return parent::save();
}