function MenuDeleteForm::submitForm

Same name in other branches
  1. 8.9.x core/modules/menu_ui/src/Form/MenuDeleteForm.php \Drupal\menu_ui\Form\MenuDeleteForm::submitForm()
  2. 10 core/modules/menu_ui/src/Form/MenuDeleteForm.php \Drupal\menu_ui\Form\MenuDeleteForm::submitForm()
  3. 11.x core/modules/menu_ui/src/Form/MenuDeleteForm.php \Drupal\menu_ui\Form\MenuDeleteForm::submitForm()

Overrides EntityDeleteFormTrait::submitForm

File

core/modules/menu_ui/src/Form/MenuDeleteForm.php, line 78

Class

MenuDeleteForm
Defines a confirmation form for deletion of a custom menu.

Namespace

Drupal\menu_ui\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
    // Locked menus may not be deleted.
    if ($this->entity
        ->isLocked()) {
        return;
    }
    // Delete all links to the overview page for this menu.
    // @todo Add a more generic helper function to the menu link plugin
    //   manager to remove links to an entity or other ID used as a route
    //   parameter that is being removed. Also, consider moving this to
    //   menu_ui.module as part of a generic response to entity deletion.
    //   https://www.drupal.org/node/2310329
    $menu_links = $this->menuLinkManager
        ->loadLinksByRoute('entity.menu.edit_form', [
        'menu' => $this->entity
            ->id(),
    ], TRUE);
    foreach ($menu_links as $id => $link) {
        $this->menuLinkManager
            ->removeDefinition($id);
    }
    parent::submitForm($form, $form_state);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.