Problem/Motivation
#2198571: menu.inc must not unset MenuLink::menu_name and #2188097: "Comment forms" links to admin/content/comment showed that if a menu link's parent item does not exist, the system does not show it, but fails later on.
The result is that invalid and incomplete menu link entities are stored for missing parent_id and it is also very hard to debug where the problem is coming from (Assume that a module is disabled and another one implicitly depends on a menu link from it).
Proposed resolution
Throw an exception when a menu link's parent link does not exist, prevents it from being saved.
Remaining tasks
None.
User interface changes
None.
API changes
None.
Comment | File | Size | Author |
---|---|---|---|
#34 | validate_default_menu-2198619-34.patch | 74.9 KB | AjitS |
#23 | interdiff.txt | 4.41 KB | Xano |
#23 | drupal_2198619_23.patch | 3.6 KB | Xano |
Comments
Comment #1
sunComment #2
XanoThis works, but
menu_router_rebuild()
catches any exception, so except for a log message there is never any evidence of this validation failure.Comment #3
dawehnerIt would be kind of better to add this exception somewhere around
in
menu_link_rebuild_defaults()
What about providing an actual named exception for non-existing parent and catch that one different, so we at least show some message?
Comment #4
BerdirComment #5
BerdirToo tired... updated the issue title and summary to clarify that the current behavior results in weird and invalid menu links being saved and notices being thrown (in HEAD) and changing to a bug report. With the validation/exception throwing as the suggested solution for
Result is the same but clarifies that this fixes an actual problem and isn't just a nice to have improvement :)
The link title is a similar case, you can right now save a menu link without a link title (for example, because you accidentally used 'title' when converting from hook_menu()), and it will happily save a menu link with a link title. I would assume that we can make the title required now, as we don't have callbacks and stuff like that anymore, so we should possibly validate and throw an exception for that too?
Comment #6
XanoWhy do you think that would be better? IMHO validation should happen as close to the input (which is the hook invocation) as possible, especially as what we're doing here is nothing application-level, but simply verify data integrity.
Comment #7
dawehnerAdding some tags
Comment #8
XanoI noticed the
description
key is not documented as either required or optional, so I added that this is optional, so the validation and documentation are in sync.We could, but I'd first like to know why
menu_router_rebuild()
catches any exception it receives in the first place, especially as exceptions are used for problems that must be fixed, before we make it re-throw only specific ones.Comment #9
dawehnerPreviously menu_router_rebuild() have been critical, as you could not rebuilt anything manually via the UI. This is not longer the case given that the menu_router is not the router anymore.
Comment #10
dawehnerWe could also check for an accident use of 'title' instead of 'link_title'. have you also thought about checking that the route name is valid?
Comment #11
XanoRedundant keys don't matter, do they?
Good one! I added that in this patch.
I also moved the validation until after the invocation of the alter hook, to make absolutely sure the definitions are valid.
Comment #12
XanoComment #14
tim.plunkettNo typed exception for any of these? :(
Also shouldn't we be able to test this now?
Comment #15
XanoNot yet, as the existing tests fail, and since the patch only introduced exceptions, the failure must be caused by one of those. However, I have not been able to get them to show up in the test results yet.
Comment #16
dawehnerThey also don't appear in the watchdog?
Comment #17
BerdirRaising to major, for the reason #2198571: menu.inc must not unset MenuLink::menu_name was re-opened. Apparently providing a wrong parent now leads to a PDO exception and this is happening a lot now because we renamed the menu links so all contrib modules that are placing admin links are now broken.
Comment #18
XanoRe-roll. No changes.
Comment #20
BerdirFound the problem, the two foreach's with by reference were messing with the links.
Comment #22
Berdir20: drupal_2198619_20.patch queued for re-testing.
Comment #23
XanoComment #24
pwolanin CreditAttribution: pwolanin commentedwhy are we using sprintf?
Comment #25
pwolanin CreditAttribution: pwolanin commentedAlso, there is code now that's incorrect that unsets menu name in certain cases during the save. I don't know that this patch makes sense in general.
I don't think validating the actual route is worth the code in term of time and memory.
Comment #26
dawehnerWe should certainly validate the menu links in case we are in a development enviroment, much like we should do route definition validation in case we have that mode.
Comment #27
XanoI haven't looked through #2226761: Change all default settings and config to fast/safe production values in detail yet, but that's in now (#26 looks like it referenced that issue).
Comment #28
pwolanin CreditAttribution: pwolanin commentedshould possibly postpone on this? #2256521: [META] New plan, Phase 2: Implement menu links as plugins, including static admin links and views, and custom links with menu_link_content entity, all managed via menu_ui module
Comment #29
pwolanin CreditAttribution: pwolanin commentedLets postpone this issue until: #2256521: [META] New plan, Phase 2: Implement menu links as plugins, including static admin links and views, and custom links with menu_link_content entity, all managed via menu_ui module
Comment #30
pwolanin CreditAttribution: pwolanin commentedComment #31
pwolanin CreditAttribution: pwolanin commentedComment #32
mgiffordUnblocked I think.
Comment #33
dawehnerMaybe this helps to trigger some initiative in xano :P
Comment #34
AjitSPlain reroll
Comment #36
pwolanin CreditAttribution: pwolanin commentedSorry, but that's a completely incorrect re-roll In #34 - this patch needs to be rewritten since the menu link save code is no longer in menu.inc.
Comment #37
pwolanin CreditAttribution: pwolanin commentedIn fact, I think the basic problem is fixed in MenuTreStorage::findParent()
It validates the parent there - if it doesn't exist, the link goes to the top level with an empty parent.
I'm pretty sure we handle invalid route name at render time.