You are here

public function NewsletterForm::save in Simplenews 3.x

Same name and namespace in other branches
  1. 8.2 src/Form/NewsletterForm.php \Drupal\simplenews\Form\NewsletterForm::save()
  2. 8 src/Form/NewsletterForm.php \Drupal\simplenews\Form\NewsletterForm::save()

Overrides Drupal\Core\Entity\EntityForm::save().

Overrides EntityForm::save

File

src/Form/NewsletterForm.php, line 212

Class

NewsletterForm
Base form for category edit forms.

Namespace

Drupal\simplenews\Form

Code

public function save(array $form, FormStateInterface $form_state) {
  $newsletter = $this->entity;
  $status = $newsletter
    ->save();
  $edit_link = \Drupal::linkGenerator()
    ->generate($this
    ->t('Edit'), $this->entity
    ->toUrl());
  if ($status == SAVED_UPDATED) {
    $this
      ->messenger()
      ->addMessage($this
      ->t('Newsletter %label has been updated.', [
      '%label' => $newsletter
        ->label(),
    ]));
    \Drupal::logger('simplenews')
      ->notice('Newsletter %label has been updated.', [
      '%label' => $newsletter
        ->label(),
      'link' => $edit_link,
    ]);
  }
  else {
    $this
      ->messenger()
      ->addMessage($this
      ->t('Newsletter %label has been added.', [
      '%label' => $newsletter
        ->label(),
    ]));
    \Drupal::logger('simplenews')
      ->notice('Newsletter %label has been added.', [
      '%label' => $newsletter
        ->label(),
      'link' => $edit_link,
    ]);
  }
  $form_state
    ->setRedirect('simplenews.newsletter_list');
}