You are here

public function EncryptionProfileForm::save in Encrypt 8.3

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

File

src/Form/EncryptionProfileForm.php, line 361

Class

EncryptionProfileForm
Provides the form to add / edit an EncryptionProfile entity.

Namespace

Drupal\encrypt\Form

Code

public function save(array $form, FormStateInterface $form_state) {
  $encryption_profile = $this->entity;
  $status = $encryption_profile
    ->save();
  if ($status) {
    $this
      ->messenger()
      ->addMessage($this
      ->t('Saved the %label encryption profile.', [
      '%label' => $encryption_profile
        ->label(),
    ]));
  }
  else {
    $this
      ->messenger()
      ->addMessage($this
      ->t('The %label encryption profile was not saved.', [
      '%label' => $encryption_profile
        ->label(),
    ]));
  }
  $form_state
    ->setRedirectUrl($encryption_profile
    ->toUrl('collection'));
}