Apologies if this has already been captured somewhere else. I did a search on the issue queue but couldn't see anything as explicitly stated as this... Though I find it hard to believe that nobody has encountered this issue before. Feel free to close as a duplicate if this is the case. The most similar issue I could find (for D7) has been linked.

Problem/Motivation

When a menu item with nested children is moved from one menu to the other... Those children items' menu settings are NOT updated. The child links appear in the new menu, but the menu link edit and node edit forms do not reflect this so any update will result in the link being moved to the root of the original menu.Steps to reproduce

  1. Create a https://simplytest.me/ instance for Drupal core 8.4 dev (plus the devel module to speed up bulk creation of test content)
  2. Enable the 'Devel generate' module (/admin/modules)
  3. Mass create 50 'Basic page' nodes (/admin/config/development/generate/content)
  4. Edit the main menu and add a number of these nodes (make sure some are nested as children at least 2 levels deep)
  5. Create a new menu (/admin/structure/menu/add)
  6. Make sure that newly created menu is selected for the 'Basic page' content type (/admin/structure/types/manage/page)
  7. Edit any parent node at least 1 level deep with nested children, either within the menu link edit form or the node edit form
  8. Change the menu parent item for that node to be at the root of the newly created menu (under 'Menu settings')
  9. Visit the newly created menu admin page and verify that the parent/children menu items are present (all moved across from the above step)
  10. Edit any of the children items. The 'Parent link' field is now automatically set to the root of the main menu. The same is true if you edit that child node... More problematic is that saving it will move the item back into the main menu when in fact it should stay in the new menu
  11. Saving the menu structure from the admin page doesn't seem to make a difference

Proposed resolution

Ideally when a menu item is moved; the children menu item node/s should be updated accordingly. If this is not possible then a warning message should at least be displayed to the user letting them know of this limitation. Otherwise if a user follows the instructions above and then edits a child menu item; they will unintentionally move the menu item back to the root of the 'Main menu'.

Remaining tasks

Implement fix as per 'Proposed resolution' if simple enough to do so. Otherwise have a discussion about the best way to tackle this problem.

User interface changes

Unsure

API changes

Unsure but unlikely

Data model changes

Unsure

Comments

marc.groth created an issue. See original summary.

justcaldwell’s picture

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

Confirming that this is still an issue as of 8.6.4.

Other than problem of affected menu items potentially being unintentionally moved to another menu described above, this causes problems for the contrib module Menu Admin per Menu, which relies on the menu name to grant update access to menu link content.

larowlan’s picture

Priority: Normal » Major

Given the data integrity issues here, this is more likely major

larowlan’s picture

Title: Moving a nested menu item does not update the children » Moving a nested menu item via the node edit form does not update menu of the children
larowlan’s picture

Title: Moving a nested menu item via the node edit form does not update menu of the children » Moving a nested menu item via the link edit form or node edit form does not update menu of the children
pameeela’s picture

Issue summary: View changes

Updated issue summary to reflect my findings.

This is major because the menu links appear to be in the right place and simply editing the node will move it to the root of the main menu. Just encountered this on a site with a lot of menu links and I thought I found an easy fix by simply moving the parent, but eventually realised each child has to be manually set regardless.

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.

nikolay.sh’s picture

Hello,
We are faced with the same issue. Prepared the patch to force update menu name for all childs menu items.

pameeela’s picture

Status: Active » Needs review
samiullah’s picture

Looks good

Steps followed

  1. Create a https://simplytest.me/ instance for Drupal core 8.9 dev (plus the devel module to speed up bulk creation of test content)
  2. Enable the 'Devel generate' module (/admin/modules)
  3. Mass create 50 'Basic page' nodes (/admin/config/development/generate/content)
  4. Edit the main menu and add a number of these nodes (make sure some are nested as children at least 2 levels deep)
  5. Create a new menu (/admin/structure/menu/add)
  6. Make sure that newly created menu is selected for the 'Basic page' content type (/admin/structure/types/manage/page)
  7. Edit any parent node at least 1 level deep with nested children, either within the menu link edit form or the node edit form
  8. Change the menu parent item for that node to be at the root of the newly created menu (under 'Menu settings')
  9. Visit the newly created menu admin page and verify that the parent/children menu items are present (all moved across from the above step)

This can be moved to RTBC after proper code review
Thanks

larowlan’s picture

@nikolay.sh please don't add all those tests, each one costs the DA $$

larowlan’s picture

+++ b/core/modules/menu_link_content/src/Entity/MenuLinkContent.php
@@ -236,6 +236,16 @@ public function postSave(EntityStorageInterface $storage, $update = TRUE) {
+    // If menu name has been changed need to set the proper menu name for all child items.

this needs to be less than 80 chars for php-cs sake

We need some test-coverage here to demonstrate the issue is solved.

jungle’s picture

>@nikolay.sh please don't add all those tests, each one costs the DA $$

FYI, @samiullah did add the rest I think. Checked two of them :)

larowlan’s picture

oh apologies, no harm done, I cancelled all the extra ones - just for next time :)

id.aleks’s picture

LGTM. But most likely we need to write the hook_update that will fix the Parent Item for the existing menu items. In any case path works for me. Nice work @nikolay.sh.

samiullah’s picture

Apologies will take care of not running automated tests next time to save D$ :)

quietone’s picture

Status: Needs review » Needs work

Setting to NW for the comment in #13 and tests.

ayushmishra206’s picture

Version: 8.9.x-dev » 9.2.x-dev
StatusFileSize
new886 bytes
new981 bytes

Made the change requested in #13. Tests still remain to be added.

mohit_aghera’s picture

Assigned: Unassigned » mohit_aghera
mohit_aghera’s picture

Status: Needs work » Needs review
StatusFileSize
new4.02 KB
new3.08 KB
new3.06 KB

- Adding test cases and test-only patches. Let's see how it goes.

Status: Needs review » Needs work

The last submitted patch, 21: test-only-2954418-20.patch, failed testing. View results

mohit_aghera’s picture

Assigned: mohit_aghera » Unassigned
Status: Needs work » Needs review
Issue tags: -Needs tests

Changing status to Needs review as failure is in test-only patch.

weseze’s picture

Just tried this patch (8.9.x version) and it works brilliantly for me. Moved a menu structure with 20 pages, 3 levels deep from 1 menu to another without issue.
I am however a bit concerned when moving much larger trees. Can this not cause issues? (out-of-memory or just very large load times) And if so, when does it become a concern? 100 menu-links, 1000, 1.000.000, ...?

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

marc.groth’s picture

This is looking really good but I am still having some issues with the latest patch unfortunately. I'll explain.

I edited the parent of a large menu section within an existing menu to move it into a new one. This worked well and all of the children are present on this new menu page.

However: the children nodes don't actually seem to be updated/associated. If I go to edit any of the children nodes; the 'Parent link' is set to the root of the original menu that the section was copied from. Worse so; if I save that node without making any changes; then the structure that this node (and it's children) sat in are no longer in the new menu where they should be (and are now instead in the root of the original menu).

I tried clearing the cache and running cron a number of times to no avail.

So it looks like the children items are moved across; but the association of them is not quite correct as they are automatically assumed to be part of the root of the original menu (when the relevant node is edited/saved).

Hope this makes sense. Happy to clarify if anything isn't clear

marc.groth’s picture

Status: Needs review » Needs work

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

mstrelan’s picture

@marc.groth is it possible that the new menu is not configured as an "available menu" for the node type?

mstrelan’s picture

Status: Needs work » Needs review

Setting back to needs review as I believe the issue in #26 was a configuration error. Feel free to change back if that's not the case.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new154 bytes

The Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.