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(), 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.