Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion src/MenuFormController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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.
*
Expand Down
2 changes: 1 addition & 1 deletion src/MenuFormLinkController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
1 change: 0 additions & 1 deletion src/MenuSliceFormController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down