You are here

MegaMenuDelete.php in The Better Mega Menu 2.x

Same filename and directory in other branches
  1. 8 src/Form/MegaMenuDelete.php

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;

/**
 * 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());
  }

}

Classes

Namesort descending Description
MegaMenuDelete Builds the form to delete a megamenu.