A menu link must have at least one visible (hidden = 0) child menu link for its has_children value to be set to 1, if there are no children or all the children of a menu link are hidden, has_children will be 0 - see the _menu_update_parental_status() function.

The value of has_children is used to determine whether the expanded class is added to a menu link (if has_children evaluates to TRUE, expanded is added etc), this makes perfect sense but has_children is also checked in the _menu_delete_item() function where, depending on its value, child menu links are loaded, re-parented and saved or orphaned.

  • If has_children evaluates to TRUE (there is at least one child menu link and it's visible) - all child menu links regardless of visibility are loaded, re-parented and saved.
  • If has_children evaluates to FALSE (there are no child menu links or all child menu links are hidden) - the process is skipped, any hidden child menu links are orphaned - their plid no longer exists.

The attached patch simply removes the has_children check in _menu_delete_item() so that regardless of the hidden status of child menu links they are re-parented correctly.

Comments

Status: Needs review » Needs work

The last submitted patch, remove_has_children_check_menu_delete_item.patch, failed testing.

matason’s picture

Version: 8.x-dev » 7.x-dev
Status: Needs work » Needs review
StatusFileSize
new2.81 KB

Changed version to 7.x-dev, attached patch which now includes tests.

chx’s picture

Status: Needs review » Needs work

If this is the case why it's called has_children instead of has_visible_children? It's not an adequate answer because chx named it so! I am allowed to make mistakes too :) Looking at how has_children is used to set expanded/collapsed it'd be a more adequate name. It'd be a very easy upgrade function and a search-replace.

chx’s picture

Version: 7.x-dev » 8.x-dev

Also things like this go into 8.x first.

xjm’s picture

Issue tags: +Needs backport to D7

Tagging.

matason’s picture

xjm, chx thanks for your comments here and for your help on IRC, I'll work on another patch around changing the column name and I'll also add some more tests for ensuring correct handling of visible descendants on parent menu link deletion, this works as I would expect but we currently don't test it.

matason’s picture

I've been looking at the tests in modules/simpletest/tests/menu.test and in particular testMenuLinkReparenting() as that seems to be the place for additional tests for this issue...

It appears to me that testMenuLinkReparenting() is really testing the menu's ability to heal itself when bad things happen: we set up the conditions in the test and call assertMenuLinkParents() which includes a menu_link_save() on all the menu links before the assert is done. Whilst that's fine for testing the self-healing capabilities of the menu the additional menu_link_save() in the assert creates false conditions for testing just re-parenting.

So I just wanted to sanity check my thinking really, does it seem sensible to separate the test into two tests: a) tests around self-healing (with the additional menu_link_save()) and b) tests around reparenting (without the additional menu_link_save()).

matason’s picture

Status: Needs work » Needs review
StatusFileSize
new30.62 KB

The attached patch:

  • Renames the has_children column of the menu_links table to has_visible_children
  • Updates code and comments to reflect this change
  • Adds another level of menu links in createMenuHierarchy() so that successful re-parenting to an ancestor (rather than top-level) can be tested
  • Removes the has_children check in _menu_delete_item() that previously prevented correct re-parenting of descendant hidden menu links when all descendants were hidden
  • Adds a test for the above
  • Moves the menu_link_save() out of assertMenuLinkParents() into a new method, repairLinkHierarchy()
chx’s picture

Great -- needs an update function but i am behind with #1182290: Add boilerplate upgrade path tests give me a few days on that.

matason’s picture

Status: Needs review » Needs work

Thanks @chx. Yes, update function - I'll re-roll the patch with that included.

matason’s picture

Status: Needs work » Needs review
StatusFileSize
new31.43 KB

The attached patch contains everything in #8 plus implements hook_update_N() in system.install to change menu_links.has_children to menu_links.has_visible_children.

sun’s picture

The schema change cannot be backported to D7. (sorry, that's obvious, don't have time for more right now.)

kscheirer’s picture

Status: Needs review » Needs work

The last submitted patch, remove_has_children_check-1258014-11.patch, failed testing.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

pameeela’s picture

Issue summary: View changes
Status: Needs work » Closed (outdated)
Issue tags: +Bug Smash Initiative

This code is long gone and it doesn't look like it's still valid in the current implementation. I also tested this manually and it worked as expected:

  1. Added a parent link
  2. Added some child links and disabled them
  3. Deleted the parent link
  4. Child links were re-parented up a level