You are here

TokenCustomDeleteForm.php in Custom Tokens 8

File

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

namespace Drupal\token_custom\Form;

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

/**
 * Provides a confirmation form for deleting a custom token entity.
 */
class TokenCustomDeleteForm extends ContentEntityConfirmFormBase {

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

  /**
   * {@inheritdoc}
   */
  public function getCancelUrl() {
    return new Url('entity.token_custom.collection');
  }

  /**
   * {@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();
    $form_state
      ->setRedirect('entity.token_custom.collection');
  }

}

Classes

Namesort descending Description
TokenCustomDeleteForm Provides a confirmation form for deleting a custom token entity.