You are here

public function DataPolicyRevisionEdit::save in Data Policy 8

Form submission handler for the 'save' action.

Normally this method should be overridden to provide specific messages to the user and redirect the form after the entity has been saved.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

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

Overrides DataPolicyForm::save

File

src/Form/DataPolicyRevisionEdit.php, line 119

Class

DataPolicyRevisionEdit
Provides a form for editing a Data policy revision.

Namespace

Drupal\data_policy\Form

Code

public function save(array $form, FormStateInterface $form_state) {
  if (!empty($form_state
    ->getValue('active_revision')) && !$this->entity
    ->isDefaultRevision()) {
    $this->entity
      ->isDefaultRevision(TRUE);
    $config = $this->configFactory
      ->getEditable('data_policy.data_policy');
    $ids = $config
      ->get('revision_ids');
    $ids[$this->entity
      ->getRevisionId()] = TRUE;
    $config
      ->set('revision_ids', $ids)
      ->save();
  }
  $this->entity
    ->save();
  $this
    ->messenger()
    ->addStatus($this
    ->t('Saved revision.'));
  $form_state
    ->setRedirect('entity.data_policy.version_history', [
    'entity_id' => $this->entity
      ->id(),
  ]);
}