Problem/Motivation
The db column "has_children" in the table "menu_links" is a flag which marks if a menu item is a parent menu item. Its default is 0, i. e. no children. Once another menu item becomes a child, e. g. by creating or moving, the flag is set to 1, i. e. has children. When all children are moved away from its parent, the parent's "has_children" flag doesn't change, i. e. it still remains 1 which is wrong.
The problem comes with theming as menu item with children obtain the CSS class "collapsed". Obviously there's a work around in the theme, but the attached core patch addresses the problem of updating the parent menu item's "has_children" status when moving child menu items. Deletion and creation of child menu item should update the flag as expected.
The bug occurs when using drag and drop ordering, and when the child item is moved above the parent item, causing the weight of the parent item to change. When this happens, the triangle icon that indicates a menu item has a child does not disappear. In addition, the css class of the menu item that used to be a parent will retain the li class="collapsed".
Steps to repeat:
- Install Drupal
- Create new menu -- Home/Administration/Structure /admin/structure/menu
- Give the new menu a title and save
- Add new menu item at root level
- Add menu to desired block area -- Home/Administration/Structure /admin/structure/block
- View site to make sure that the new menu item in the new menu doesn't have a triangle next to it showing it to be a parent
- Go back to the new menu on the menus page -- Home/Administration/Structure /admin/structure/menu
- Select your new menu by clicking edit menu to the right of the menu's name
- Add a new menu item and make it a child of the first menu item by dragging it underneath the original menu item and to the right
- View site to make sure that the new menu item in the new menu has a triangle next to it showing it to be the parent of the new menu item
- Go back to the new menu on the menus page -- Home/Administration/Structure /admin/structure/menu
- Select your new menu by clicking edit menu to the right of the menu's name
- Move the new menu item to the left to make it on the same level as the original menu item and no longer its child
- View site to make sure that the new menu item in the new menu doesn't have a triangle next to it showing it to be a parent
Proposed resolution
If the child item is saved before the original parent, it will correctly update the 'has_children' flag of the parent (see moveChildren()). When the parent is saved later on it will overwrite it with the original value again.
We have to make sure the original parent item is saved before the child item. This has to be solved in MenuFormController::submitOverviewForm(). Here the order is determined in which the items are saved.
Remaining tasks
Test written and needs reviews.
Original report by [username]
The db column "has_children" in the table "menu_links" is a flag which marks if a menu item is a parent menu item. Its default is 0, i. e. no children. Once another menu item becomes a child, e. g. by creating or moving, the flag is set to 1, i. e. has children. When all children are moved away from its parent, the parent's "has_children" flag doesn't change, i. e. it still remains 1 which is wrong.
The problem comes with theming as menu item with children obtain the CSS class "collapsed". Obviously there's a work around in the theme, but the attached core patch addresses the problem of updating the parent menu item's "has_children" status when moving child menu items. Deletion and creation of child menu item should update the flag as expected.