You are here

CityListDeleteForm.php in Country, State and City Fields 8

File

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

namespace Drupal\country_state_city\Form;

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

/**
 * Provides a form for deleting a citylist entity.
 *
 * @ingroup country_state_city
 */
class CityListDeleteForm extends ContentEntityConfirmFormBase {

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

  /**
   * {@inheritdoc}
   *
   * If the delete command is canceled, return to the slider list.
   */
  public function getCancelUrl() {
    return new Url('entity.citylist.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();
    $this
      ->logger('citylist')
      ->notice('@type: deleted %title.', [
      '@type' => $this->entity
        ->bundle(),
      '%title' => $this->entity
        ->label(),
    ]);
    $form_state
      ->setRedirect('entity.citylist.collection');
  }

}

Classes

Namesort descending Description
CityListDeleteForm Provides a form for deleting a citylist entity.