You are here

public function SynonymForm::save in Synonyms 2.0.x

Same name and namespace in other branches
  1. 8 src/Form/SynonymForm.php \Drupal\synonyms\Form\SynonymForm::save()

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/SynonymForm.php, line 200

Class

SynonymForm
Entity form for 'synonym' config entity type.

Namespace

Drupal\synonyms\Form

Code

public function save(array $form, FormStateInterface $form_state) {
  $status = $this->entity
    ->save();
  if ($status) {
    $this
      ->messenger()
      ->addStatus($this
      ->t('Saved the %label synonym configuration.', [
      '%label' => $this->entity
        ->label(),
    ]));
  }
  else {
    $this
      ->messenger()
      ->addError($this
      ->t('The %label synonym configuration was not saved.', [
      '%label' => $this->entity
        ->label(),
    ]));
  }
  $form_state
    ->setRedirect('synonym.entity_type.bundle', [
    'synonyms_entity_type' => $this->controlledEntityType,
    'bundle' => $this->controlledBundle,
  ]);
}