X-Git-Url: http://aleph1.co.uk/gitweb/?a=blobdiff_plain;ds=sidebyside;f=web%2Fcore%2Fmodules%2Fmenu_ui%2Fsrc%2FForm%2FMenuDeleteForm.php;fp=web%2Fcore%2Fmodules%2Fmenu_ui%2Fsrc%2FForm%2FMenuDeleteForm.php;h=1cebd9091c2f41af3bb4ce834e0780b0778d6ae3;hb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;hp=0000000000000000000000000000000000000000;hpb=57c063afa3f66b07c4bbddc2d6129a96d90f0aad;p=yaffs-website diff --git a/web/core/modules/menu_ui/src/Form/MenuDeleteForm.php b/web/core/modules/menu_ui/src/Form/MenuDeleteForm.php new file mode 100644 index 000000000..1cebd9091 --- /dev/null +++ b/web/core/modules/menu_ui/src/Form/MenuDeleteForm.php @@ -0,0 +1,96 @@ +menuLinkManager = $menu_link_manager; + $this->connection = $connection; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container) { + return new static( + $container->get('plugin.manager.menu.link'), + $container->get('database') + ); + } + + /** + * {@inheritdoc} + */ + public function getDescription() { + $caption = ''; + $num_links = $this->menuLinkManager->countMenuLinks($this->entity->id()); + if ($num_links) { + $caption .= '

' . $this->formatPlural($num_links, 'Warning: There is currently 1 menu link in %title. It will be deleted (system-defined items will be reset).', 'Warning: There are currently @count menu links in %title. They will be deleted (system-defined links will be reset).', ['%title' => $this->entity->label()]) . '

'; + } + $caption .= '

' . t('This action cannot be undone.') . '

'; + return $caption; + } + + /** + * {@inheritdoc} + */ + protected function logDeletionMessage() { + $this->logger('menu')->notice('Deleted custom menu %title and all its menu links.', ['%title' => $this->entity->label()]); + } + + /** + * {@inheritdoc} + */ + 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 a 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); + } + +}