You are here

public function DataPolicyForm::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 EntityForm::save

1 method overrides DataPolicyForm::save()
DataPolicyRevisionEdit::save in src/Form/DataPolicyRevisionEdit.php
Form submission handler for the 'save' action.

File

src/Form/DataPolicyForm.php, line 66

Class

DataPolicyForm
Default form controller for Data policy.

Namespace

Drupal\data_policy\Form

Code

public function save(array $form, FormStateInterface $form_state) {
  $active_revision = !empty($form_state
    ->getValue('active_revision'));
  $new_revision = !empty($form_state
    ->getValue('new_revision'));
  if ($active_revision) {
    $this->entity
      ->isDefaultRevision(TRUE);
  }
  else {
    $this->entity
      ->isDefaultRevision(FALSE);
  }
  if ($new_revision) {
    $this->entity
      ->setNewRevision(TRUE);
    $this->entity
      ->setRevisionCreationTime($this->time
      ->getRequestTime());
    $this->entity
      ->setRevisionUserId($this
      ->currentUser()
      ->id());
    $this
      ->messenger()
      ->addStatus($this
      ->t('Created new revision.'));
  }
  return parent::save($form, $form_state);
}