Warn user when entity delete will cause menu item re-parenting

Created on 15 September 2023, 9 months ago
Updated 27 February 2024, 4 months ago

Problem/Motivation

Deleting an entity in the middle/top of the menu tree causes unexpected results for content editors.

Steps to reproduce

  1. Install Drupal Core
  2. Create some entities
  3. Build out a simple main menu tree. For example:
    Menu item 1
    Menu item 2
       |- Menu item 2.a
       |- Menu item 2.b
       |- Menu item 2.c
    Menu item 3
    Menu item 4
    

3. Either delete the "Menu item 2" node, or menu item.

Woah, all of a sudden the main navigation (site-wide) has three new top-level menu items! This is even more of a surprise if the "Menu item 2" menu item was disabled, or the related entity was unpublished (because you would've forgotten that it has menu children).

Proposed resolution

Warn before the delete (but we can't do that everywhere), and notify after the delete.

Pre-delete warning

Delete forms currently:

Are you sure you want to delete the content item ?
This action cannot be undone.

Update delete forms with informational text:

This content has 3 menu children. Proceeding will move these one level higher in the menu hierarchy:
* Foo (link to /admin/structure/menu/item/[id]/edit)
* Bar (link to /admin/structure/menu/item/[id]/edit)
* Baz (link to /admin/structure/menu/item/[id]/edit)

Post-delete notification

Show a warning message afterwards (same as above, just changing the verb tense):

Content was deleted that had menu children. These have been moved one level higher in the menu hierarchy:

* Foo (link to /admin/structure/menu/item/[id]/edit)
* Bar (link to /admin/structure/menu/item/[id]/edit)
* Baz (link to /admin/structure/menu/item/[id]/edit)

All entity types

We should should generalize to all entity types. e.g. " was deleted that had menu children..."

Remaining tasks

  • Complete
  • Complete
  • Complete
  • Agree on wording, and confirm that the wording in the patch is in line with what's in this description
  • Decide if/how to show menu items that the user doesn't have access to
  • Confirm that code changes work for all entity types (including deleting a menu item with children)
  • Confirm that tests are thorough

User interface changes

  • Messages on delete form.
  • Message via messenger after entity is deleted via entity delete form.

API changes

None

Data model changes

None

Release notes snippet

TBD

โœจ Feature request
Status

Needs work

Version

11.0 ๐Ÿ”ฅ

Component
Menu systemย  โ†’

Last updated 1 day ago

Created by

๐Ÿ‡จ๐Ÿ‡ฆCanada dalin Guelph, ๐Ÿ‡จ๐Ÿ‡ฆ, ๐ŸŒ

Live updates comments and jobs are added and updated live.
  • Needs usability review

    Used to alert the usability topic maintainer(s) that an issue significantly affects (or has the potential to affect) the usability of Drupal, and their signoff is needed. When adding this tag, make it easy to review the issue. Make sure the issue summary describes the problem and the proposed solution. Screenshots usually help a lot! To get sign-off on issues with the "Needs usability review" tag, post about them in the #ux channel on Drupal Slack, and/or attend a UX meeting to demo the patch and get direct feedback from designers/UX folks/product management on next steps. If an issue represents a significant new feature, UI change, or change to the general "user experience" of Drupal, use Needs product manager review instead. See the scope of responsibilities for product managers.

Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @dalin
  • ๐Ÿ‡จ๐Ÿ‡ฆCanada dalin Guelph, ๐Ÿ‡จ๐Ÿ‡ฆ, ๐ŸŒ
  • ๐Ÿ‡จ๐Ÿ‡ฆCanada dalin Guelph, ๐Ÿ‡จ๐Ÿ‡ฆ, ๐ŸŒ
  • First commit to issue fork.
  • I have added some logic that tests whether the child links are present for the link that we are deleting. If we have child elements then it shows a message(may not be correctly defined now) that this link contains child links which will be effected due to the deletion of the parent link.I am attaching the screenshots as a kickstart to this.

    We can similarly do this after the successful deletion of the link as well as described in the issue.

  • last update 8 months ago
    Custom Commands Failed
  • @utkarsh_33 opened merge request.
  • Pipeline finished with Failed
    8 months ago
    Total: 192s
    #33355
  • last update 8 months ago
    30,241 pass, 66 fail
  • Pipeline finished with Failed
    8 months ago
    Total: 697s
    #33400
  • ๐Ÿ‡จ๐Ÿ‡ฆCanada dalin Guelph, ๐Ÿ‡จ๐Ÿ‡ฆ, ๐ŸŒ

    @Utkarsh_33
    This isn't about when menu items are deleted. It's about when nodes (or I guess other entities too) within the menu are deleted.

  • ๐Ÿ‡ง๐Ÿ‡ทBrazil joaopauloc.dev

    joaopauloc.dev โ†’ made their first commit to this issueโ€™s fork.

  • Pipeline finished with Failed
    6 months ago
    Total: 160s
    #63818
  • Pipeline finished with Failed
    6 months ago
    Total: 643s
    #63825
  • Pipeline finished with Failed
    6 months ago
    Total: 204s
    #63877
  • Pipeline finished with Failed
    6 months ago
    Total: 646s
    #63878
  • ๐Ÿ‡ง๐Ÿ‡ทBrazil joaopauloc.dev

    Hi folks, I have two questions.

    First, the warning message will be displayed only for a node that has a menu item as a parent? or should we warn users since the content has any kind of reference in menus? If yes I need to update the implementation.

    In Drupal 11 the menu link is also deleted if the content is deleted. We need to update the message, I thought something like

    This page has 3 menu children. These menu links will be deleted too if you continue.

    Thanks.

  • ๐Ÿ‡จ๐Ÿ‡ฆCanada dalin Guelph, ๐Ÿ‡จ๐Ÿ‡ฆ, ๐ŸŒ

    @joaopauloc.dev
    I like how you moved to ContentEntityDeleteForm.php so that this will apply to all content, not just nodes. But I'm not sure that getQuestion() is the right place for this. There's several returns in that function, and you've just added one more. The original MR used buildForm(), and that might be a better choice. Especially since we want to also use a list.

    First, the warning message will be displayed only for a node that has a menu item as a parent? or should we warn users since the content has any kind of reference in menus?

    Only warn when an entity is being deleted, and that entity has a menu item, and that menu item has child menu items.

    In Drupal 11 the menu link is also deleted if the content is deleted. We need to update the message, I thought something like: This page has 3 menu children. These menu links will be deleted too if you continue.

    Yes, the menu item being deleted is what causes the problem that this ticket is trying to solve. But are you saying that in D11 the _children_ menu items are also blindly deleted??? I can't get https://simplytest.me/ to build D11 so that I can confirm. But if that's the case, then that's a separate critical issue of content destruction. I'm guessing that's _not_ happening.

    I've updated the ticket description to have clearer messaging. Can you take a look?

  • ๐Ÿ‡ง๐Ÿ‡ทBrazil joaopauloc.dev

    Thank you @dalin for the feedback.

    I'll adjust the menu to warn only on the criteria that you mentioned. Also, fix the getQuestion things that you mentioned.

    Regarding the menu item also been deleted I'll confirm one more time but I'm almost sure that was deleted too.

    I'll work on this issue until this weekend and let you know.
    thanks.

  • Assigned to joaopauloc.dev
  • ๐Ÿ‡ง๐Ÿ‡ทBrazil joaopauloc.dev

    Hey @dalin, I could confirm that only the menu item of the content was deleted.
    Working on the issue...

  • Pipeline finished with Failed
    6 months ago
    Total: 165s
    #73776
  • Pipeline finished with Failed
    6 months ago
    Total: 162s
    #73780
  • Issue was unassigned.
  • ๐Ÿ‡ง๐Ÿ‡ทBrazil joaopauloc.dev

    Updated the implementation to show the warning message before and after the content is deleted.
    Missing unit tests and fixing probably unit test issues.

  • Pipeline finished with Failed
    6 months ago
    Total: 612s
    #73782
  • Pipeline finished with Success
    5 months ago
    Total: 502s
    #79891
  • Status changed to Needs review 5 months ago
  • Status changed to RTBC 5 months ago
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia arunkumark Coimbatore

    The MR 5807 applied cleanly. The patch working as expected. Attached screenshot of manual testing.

  • Status changed to Needs work 5 months ago
  • ๐Ÿ‡ธ๐Ÿ‡ฐSlovakia poker10

    What will happe, if there will be hundreds of child menu items? I suppose this will not look good. Do we need to print the child menu items?

    I think we need to add a test for this new feature, so that we can confirm that the extra message is here, when the menu item has children and that the message is not there, when deleting a menu item without child items. Thanks!

  • Assigned to dpi
  • ๐Ÿ‡ฆ๐Ÿ‡บAustralia dpi Perth, Australia

    Working on this recently.

  • Pipeline finished with Failed
    5 months ago
    Total: 205s
    #89214
  • Pipeline finished with Failed
    5 months ago
    Total: 155s
    #89220
  • Pipeline finished with Failed
    5 months ago
    Total: 169s
    #89225
  • Pipeline finished with Failed
    5 months ago
    Total: 481s
    #89228
  • Pipeline finished with Success
    5 months ago
    Total: 2860s
    #89237
  • Pipeline finished with Failed
    5 months ago
    Total: 183s
    #90182
  • Pipeline finished with Failed
    5 months ago
    Total: 174s
    #90201
  • Pipeline finished with Success
    5 months ago
    Total: 559s
    #90206
  • Issue was unassigned.
  • Status changed to Needs review 5 months ago
  • ๐Ÿ‡ฆ๐Ÿ‡บAustralia dpi Perth, Australia

    I took a look at the existing MR5807, and found some issues in my review:

    • The moderation state change looks irrelevant.
    • The changes here should work with any entity, not just nodes.
    • Shouldnt get menu items by menu link content entity to get descendants, via entity queries.
    • The menu renders lists with HTML in t-strings, Markup elements, etc.

    Rather than add feedback to the MR, I've started from scratch as I dont think the code is usable.

    Notes on the new implementation at MR6479:

    • Uses a similar method to `menu_ui_get_menu_link_defaults()` to determine the menu link of the entity in context.
    • Renders with the standard menu builder. Which uses a proper list element instead of markup
    • Reworded warning message, use singular labels instead of _content_
    • Used formatplural, depending on number of child menu items.
    • Created a internal class service, without service id. Instead of using the old classResolver pattern.
    • In line with hooks, the new form alter is not overridable:
      • the class been finalised.
      • no service ID.
      • This was chosen as it's possible to easily unfinalise or add a service ID in the future (new issue) if we decide thats needed. Doing the reverse is not possible without dealing with backwards compatibility and deprecations.
    • update the used `getTranslationFromContext` method with a generic, so PHPStan knows its @return-ing the same entity type as is passed into the parameter.
    • Test coverage.

    Screenshots

    Single menu item child

    Multiple menu item children

    Message after delete:

    Re: @poker10 feedback in #17,

    > What will happen, if there will be hundreds of child menu items?

    The message will only return the direct children. Not multiple levels down.

    > I think we need to add a test for this new feature

    Added. I think the tests are comprehensive.

  • ๐Ÿ‡ฆ๐Ÿ‡บAustralia dpi Perth, Australia

    Added notes to review. Remains _Needs review_.

  • Pipeline finished with Success
    5 months ago
    Total: 605s
    #91018
  • ๐Ÿ‡ฆ๐Ÿ‡บAustralia dpi Perth, Australia

    Removed "node" references from issue summary.

  • ๐Ÿ‡ฆ๐Ÿ‡บAustralia dpi Perth, Australia
  • Status changed to Needs work 5 months ago
  • ๐Ÿ‡จ๐Ÿ‡ฆCanada dalin Guelph, ๐Ÿ‡จ๐Ÿ‡ฆ, ๐ŸŒ

    I've discovered that this also includes a menu entity delete. Updating the description accordingly. I updated the remaining tasks.

    IMO we don't need to do anything special if there are lots (a hundred?) direct children. The list will be long. So be it. But this will almost never happen in real life.

  • ๐Ÿ‡จ๐Ÿ‡ฆCanada dalin Guelph, ๐Ÿ‡จ๐Ÿ‡ฆ, ๐ŸŒ

    IMO we should still show something for menu items that the user doesn't have access to. They should be included in the total count, but in the list we should show "access denied" or something similar.

  • Status changed to Needs review 5 months ago
  • ๐Ÿ‡ฆ๐Ÿ‡บAustralia dpi Perth, Australia

    I've discovered that this also includes a menu entity delete.

    Agree this is a case worth covering, updated the MR and tests to acommodate Menu Link Content entities.

    we don't need to do anything special if there are lots (a hundred?) direct children. The list will be long. So be it. But this will almost never happen in real life.

    I think it'd be more common than "almost never", but I think since the menu system is already capable of rendering the menu items to the front end in runtime, then it will also be fine for backend tasks.

    Nothing further required for the item.

    IMO we should still show something for menu items that the user doesn't have access to. They should be included in the total count, but in the list we should show "access denied" or something similar.

    I disagree, I dont think theres a case in Drupal where we inform the user there is some secret data the user doesnt know about but is affected by an operation, except when permission to do the operation straight up denies the user.

    To me, only exposing data relevant to the user is sufficient.

    ----

    Changes in MR.

  • Pipeline finished with Success
    5 months ago
    Total: 622s
    #91823
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    Seems next remaining task is to agree on wording. UX team should have a say in that.

  • Status changed to Needs work 4 months ago
  • The Needs Review Queue Bot โ†’ tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".

    This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

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

Production build 0.69.0 2024