tb_megamenu-8.x-1.0-beta2/src/Form/MegaMenuDelete.php
src/Form/MegaMenuDelete.php
<?php
namespace Drupal\tb_megamenu\Form;
use Drupal\Core\Entity\EntityConfirmFormBase;
use Drupal\Core\Url;
use Drupal\Core\Form\FormStateInterface;
/**
* Builds the form to delete a megamenu.
*/
class MegaMenuDelete extends EntityConfirmFormBase {
/**
* {@inheritdoc}
*/
public function getQuestion() {
return $this->t('Are you sure you want to delete %name?', ['%name' => $this->entity->menu]);
}
/**
* {@inheritdoc}
*/
public function getCancelUrl() {
return new Url('entity.tb_megamenu.collection');
}
/**
* {@inheritdoc}
*/
public function getConfirmText() {
return $this->t('Delete');
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$this->entity->delete();
$this->messenger()->addStatus($this->t('MegaMenu %label has been deleted.', ['%label' => $this->entity->menu]));
$form_state->setRedirectUrl($this->getCancelUrl());
}
}
