You are here

public function CorrespondingReferenceForm::save in Corresponding Entity References 8.4

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/CorrespondingReferenceForm.php, line 120

Class

CorrespondingReferenceForm
Form handler for corresponding reference add and edit forms.

Namespace

Drupal\cer\Form

Code

public function save(array $form, FormStateInterface $form_state) {

  /** @var CorrespondingReferenceInterface $correspondingReference */
  $correspondingReference = $this->entity;
  $status = $correspondingReference
    ->save();
  if ($status) {
    $this
      ->messenger()
      ->addStatus($this
      ->t('Saved the %label corresponding reference.', [
      '%label' => $correspondingReference
        ->label(),
    ]));
  }
  else {
    $this
      ->messenger()
      ->addStatus($this
      ->t('The %label corresponding reference was not saved.', [
      '%label' => $correspondingReference
        ->label(),
    ]));
  }
  $form_state
    ->setRedirect('entity.corresponding_reference.collection');
}