MegaMenuDelete.php in The Better Mega Menu 2.x
File
src/Form/MegaMenuDelete.php
View source
<?php
namespace Drupal\tb_megamenu\Form;
use Drupal\Core\Entity\EntityConfirmFormBase;
use Drupal\Core\Url;
use Drupal\Core\Form\FormStateInterface;
class MegaMenuDelete extends EntityConfirmFormBase {
public function getQuestion() {
return $this
->t('Are you sure you want to delete %name?', [
'%name' => $this->entity->menu,
]);
}
public function getCancelUrl() {
return new Url('entity.tb_megamenu.collection');
}
public function getConfirmText() {
return $this
->t('Delete');
}
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());
}
}