ajax_dashboard-8.x-2.x-dev/src/Form/AJAXDashboardDeleteForm.php
src/Form/AJAXDashboardDeleteForm.php
<?php
namespace Drupal\ajax_dashboard\Form;
use Drupal\Core\Entity\EntityConfirmFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
/**
* Class AJAXDashboardDeleteForm.
*
* @ingroup ajax_dashboard
*
* @package Drupal\ajax_dashboard\Form
*
* Provides a form for deleting a ajax_dashboard_entity entity.
*/
class AJAXDashboardDeleteForm 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('entity.ajax_dashboard.collection');
}
/**
* {@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('AJAX Dashboard Entity %label has been deleted.', ['%label' => $this->entity->label()]));
$form_state->setRedirectUrl($this->getCancelUrl());
}
}
