You are here

ModalDeleteForm.php in Modal 8.2

File

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

namespace Drupal\modal_page\Form;

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

/**
 * Class: ModalDeleteForm.
 */
class ModalDeleteForm extends ContentEntityConfirmFormBase {

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

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

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

  /**
   * {@inheritdoc}
   *
   * Delete the entity and log the event. logger() replaces the watchdog.
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    $entity = $this
      ->getEntity();
    $entity
      ->delete();
    $this
      ->logger('modal_page')
      ->notice('@type: deleted %title.', [
      '@type' => $this->entity
        ->bundle(),
      '%title' => $this->entity
        ->label(),
    ]);
    $this
      ->messenger()
      ->addStatus($this
      ->t('Modal %title deleted.', [
      '%title' => $this->entity
        ->label(),
    ]));
    $form_state
      ->setRedirect('modal_page.default');
  }

}

Classes

Namesort descending Description
ModalDeleteForm Class: ModalDeleteForm.