You are here

EnvironmentIndicatorDeleteForm.php in Environment Indicator 4.x

Same filename and directory in other branches
  1. 8.3 src/Form/EnvironmentIndicatorDeleteForm.php

File

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

namespace Drupal\environment_indicator\Form;

use Drupal\Core\Entity\EntityConfirmFormBase;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\Url;

/**
 * Provides a deletion confirmation form for environment_indicator environment.
 */
class EnvironmentIndicatorDeleteForm extends EntityConfirmFormBase {
  use StringTranslationTrait;

  /**
   * {@inheritdoc}
   */
  public function getFormId() {
    return 'environment_indicator_environment_confirm_delete';
  }

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

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

  /**
   * {@inheritdoc}
   */
  public function getDescription() {
    return $this
      ->t('Deleting a environment will make disappear the indicator.');
  }

  /**
   * {@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('Deleted environment %name.', [
      '%name' => $this->entity
        ->label(),
    ]));

    // TODO: Figure out how to log stuff to the watchdog.
    $form_state['redirect'] = 'admin/config/development/environment-indicator';
    Cache::invalidateTags([
      'content' => TRUE,
    ]);
  }

}

Classes

Namesort descending Description
EnvironmentIndicatorDeleteForm Provides a deletion confirmation form for environment_indicator environment.