You are here

NewsletterDeleteForm.php in Simplenews 3.x

File

src/Form/NewsletterDeleteForm.php
View source
<?php

namespace Drupal\simplenews\Form;

use Drupal\Core\Entity\EntityConfirmFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;

/**
 * Builds the form to delete a contact category.
 */
class NewsletterDeleteForm extends EntityConfirmFormBase {

  /**
   * {@inheritdoc}
   */
  public function getQuestion() {
    return $this
      ->t('Are you sure you want to delete %name?', [
      '%name' => $this->entity
        ->label(),
    ]);
  }

  /**
   * {@inheritdoc}
   */
  public function getCancelUrl() {
    return new Url('simplenews.newsletter_list');
  }

  /**
   * {@inheritdoc}
   */
  public function getConfirmText() {
    return $this
      ->t('Delete');
  }

  /**
   * {@inheritdoc}
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    $this->entity
      ->delete();
    $this
      ->messenger()
      ->addMessage($this
      ->t('Newsletter %label has been deleted.', [
      '%label' => $this->entity
        ->label(),
    ]));
    \Drupal::logger('simplenews')
      ->notice('Newsletter %label has been deleted.', [
      '%label' => $this->entity
        ->label(),
    ]);
    $form_state
      ->setRedirect('simplenews.newsletter_list');
  }

}

Classes

Namesort descending Description
NewsletterDeleteForm Builds the form to delete a contact category.