Same filename and directory in other branches
- 8.9.x core/modules/menu_ui/src/Form/MenuDeleteForm.php
- 9 core/modules/menu_ui/src/Form/MenuDeleteForm.php
Namespace
Drupal\menu_ui\Form
File
core/modules/menu_ui/src/Form/MenuDeleteForm.php
View source
<?php
namespace Drupal\menu_ui\Form;
use Drupal\Core\Database\Connection;
use Drupal\Core\Entity\EntityDeleteForm;
use Drupal\Core\Menu\MenuLinkManagerInterface;
use Drupal\Core\Form\FormStateInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class MenuDeleteForm extends EntityDeleteForm {
protected $menuLinkManager;
protected $connection;
public function __construct(MenuLinkManagerInterface $menu_link_manager, Connection $connection) {
$this->menuLinkManager = $menu_link_manager;
$this->connection = $connection;
}
public static function create(ContainerInterface $container) {
return new static($container
->get('plugin.manager.menu.link'), $container
->get('database'));
}
public function getDescription() {
$caption = '';
$num_links = $this->menuLinkManager
->countMenuLinks($this->entity
->id());
if ($num_links) {
$caption .= '<p>' . $this
->formatPlural($num_links, '<strong>Warning:</strong> There is currently 1 menu link in %title. It will be deleted (system-defined links will be reset).', '<strong>Warning:</strong> There are currently @count menu links in %title. They will be deleted (system-defined links will be reset).', [
'%title' => $this->entity
->label(),
]) . '</p>';
}
$caption .= '<p>' . $this
->t('This action cannot be undone.') . '</p>';
return $caption;
}
protected function logDeletionMessage() {
$this
->logger('menu')
->notice('Deleted custom menu %title and all its menu links.', [
'%title' => $this->entity
->label(),
]);
}
public function submitForm(array &$form, FormStateInterface $form_state) {
if ($this->entity
->isLocked()) {
return;
}
$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);
}
}
Classes
Name |
Description |
MenuDeleteForm |
Defines a confirmation form for deletion of a custom menu. |