From 96b2ed80ed7835bbdfa0e7cf4f2898ac4c4508ab Mon Sep 17 00:00:00 2001 From: Tom Voesenek Date: Mon, 29 Jan 2018 08:57:33 +0100 Subject: [PATCH 1/2] 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(), From 287f99d86db84b205c0fe92674b1a8955b9fde8c Mon Sep 17 00:00:00 2001 From: Tom Voesenek Date: Thu, 29 Mar 2018 14:00:05 +0200 Subject: [PATCH 2/2] Remove hardcoded fixed depth on menu slice overview. --- src/MenuSliceFormController.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/MenuSliceFormController.php b/src/MenuSliceFormController.php index e260e4f..60ad4d3 100644 --- a/src/MenuSliceFormController.php +++ b/src/MenuSliceFormController.php @@ -30,7 +30,6 @@ protected function prepareEntity() { * @inheritdoc */ protected function buildOverviewFormWithDepth(array &$form, FormStateInterface $form_state, $depth = 1, $menu_link = NULL) { - $depth = 5; // Ensure that menu_overview_form_submit() knows the parents of this form // section.