From 96b2ed80ed7835bbdfa0e7cf4f2898ac4c4508ab Mon Sep 17 00:00:00 2001 From: Tom Voesenek Date: Mon, 29 Jan 2018 08:57:33 +0100 Subject: [PATCH] Show the "edit children" link when all children are disabled --- src/MenuFormController.php | 20 +++++++++++++++++++- src/MenuFormLinkController.php | 2 +- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/MenuFormController.php b/src/MenuFormController.php index 84d7ffb..fb7a27b 100644 --- a/src/MenuFormController.php +++ b/src/MenuFormController.php @@ -214,7 +214,7 @@ public function process_links(&$form, &$links, $menu_link) { $mlid = (int)$links[$id]['#item']->link->getMetaData()['entity_id']; - if ($form['links'][$id]['#item']->hasChildren) { + if ($form['links'][$id]['#item']->hasChildren || $this->menuLinkHasChildren($links[$id]['#item'])) { if (is_null($menu_link) || (isset($menu_link) && $menu_link->id() != $mlid)) { $form['links'][$id]['title'][] = array( '#type' => 'big_menu_button', @@ -248,6 +248,24 @@ public function process_links(&$form, &$links, $menu_link) { } } + /** + * Check if the Element has any children, enabled and disabled. + * + * @param \Drupal\Core\Menu\MenuLinkTreeElement $element + * The parent element. + * + * @return bool + */ + protected function menuLinkHasChildren(MenuLinkTreeElement $element) { + $depth = $element->depth + 1; + $tree_params = new MenuTreeParameters(); + $tree_params->setMinDepth($depth); + $tree_params->setMaxDepth($depth); + $tree_params->addExpandedParents([$element->link->getPluginId()]); + $tree = $this->menuTree->load($this->entity->id(), $tree_params); + return !empty($tree); + } + /** * AJAX function called when a "Show Children" button is pressed. * diff --git a/src/MenuFormLinkController.php b/src/MenuFormLinkController.php index f6c4f3e..9f5f0f7 100644 --- a/src/MenuFormLinkController.php +++ b/src/MenuFormLinkController.php @@ -105,7 +105,7 @@ public function process_links(&$form, &$links, $menu_link) { $form['links'][$id]['root'][] = array(); - if ($form['links'][$id]['#item']->hasChildren) { + if ($form['links'][$id]['#item']->hasChildren || $this->menuLinkHasChildren($element['#item'])) { if (is_null($menu_link) || (isset($menu_link) && $menu_link != $element['#item']->link->getPluginId())) { $uri = Url::fromRoute('bigmenu.menu_link', array( 'menu' => $this->entity->id(),