Updated: Comment #0
Problem/Motivation
blocks: #2107533: Remove {menu_router}.
Proposed resolution
Remove all uses of this function, since it loads/uses data from {menu_router}
There is the possiblity that something asked the router to rebuild. If this happens in a request where you request local tasks it is NOT rebuilt yet.
Previously the menu_get_item() code took care about rebuilding it. This patch removes menu_get_item() so we set the optional rebuilding in the local task manager to ensure a fine state of the router
when you ask for all local tasks.
Remaining tasks
TODO
User interface changes
N/A
API changes
Remove API function menu_get_item()
Comment | File | Size | Author |
---|---|---|---|
#34 | menu_get_item-2177031-34.patch | 54.45 KB | Berdir |
#25 | interdiff.txt | 3.01 KB | tim.plunkett |
#25 | menu_get_item-2177031-25.patch | 54.44 KB | tim.plunkett |
Comments
Comment #1
pwolanin CreditAttribution: pwolanin commentedComment #2
XanoThose quotes summarize #2185465: menu_get_item() does not work with hook_menu_link_defaults() pretty well.
Comment #3
XanoWhat
menu_get_item()
does is try and load a menu item for a path. If it can't find an item for the given path, it removes the last path fragment and tries again.However, we no longer deal with paths, but with routes, and menu links explicitly specify the machine names of their parent links, we no longer have an easy way to find the menu item closest to a given path, as we don't have a way to move up the tree anymore, and moving down the tree is too intensive.
Comment #4
dawehnerAs menu_get_object() relies on menu_get_item() we need to solve that meta issue first.
Comment #5
catchPostponing on #2091399: [META] Remove menu_get_object().
Comment #6
catchComment #7
dawehnerNote: This removes all calls which are obvious, but leaves the one in menu.inc, which are still part of the API workflow. These can and should be cleaned up without too many problems later.
Comment #8
tim.plunkettThis is why we didn't use that already. We need that destination...
Nevermind! LOL.
This looks great.
Comment #9
dawehnerLet's invite the testbot as well.
Comment #11
dawehnerRemoved a lot of the old menu_get_item() as well as the code / tests which rely on it.
Comment #13
dawehnerThis was too agressive, let's just remove the ones we actually don't need but also remove menu_get_item() itself.
Can a maintainer add the "Approved API change", as we will remove stuff like local task support?
Comment #15
dawehnerThe general
Comment #17
dawehner15: local_task-2177031-15.patch queued for re-testing.
Comment #19
rlmumfordPHP Fatal error: Call to a member function rebuildIfNeeded() on a non-object in /var/lib/drupaltestbot/sites/default/files/checkout/core/lib/Drupal/Core/Menu/LocalTaskManager.php on line 193
Any ideas?
Comment #20
rlmumfordI've had a look and can't see anything obvious why that wouldn't be there at that point.
Comment #21
dawehnerOh, some phpunit tests fail.
Comment #22
dawehner21: menu_get_item-2177031-21.patch queued for re-testing.
Comment #23
pwolanin CreditAttribution: pwolanin commentedCan you explain why this is needed?
Also, rebuilding the routes in the middle of the manager seems a bit odd - was that a bug you ran into?
Comment #24
dawehnerThank you for your reviews!
Just have a look at: #2115025: Content admin views title saved localized to the menu table, this will explain the need for it. This patch just reapplies the same pattern.
Yes, this was a bug, see https://qa.drupal.org/pifr/test/726203
Saving a view triggers at some point a rebuild of everything, so the router system and local tasks. The notice you see exists, because the router is not rebuilt yet at that point.
The reason why this patch fails is the removal of menu_get_item(), which had a call to
integrated.
I thought about putting this into the render code as well, as there is no route provider access during the rebuild, though it seems to be something we really want to avoid be being
triggered on the actual side, unless something complex like a local task rebuild happens.
Comment #25
tim.plunkettNeeded a reroll, and had some stray comments referring to menu_get_item that I removed.
Follow-up idea: Provide a dedicated method on menu link storage (or elsewhere) for loading by route name.
I think this is ready to go, but I'm going to wait for green before reRTBCing.
Comment #26
tim.plunkettGreat! Since my only work on this issue was doc fixing at the end, I feel okay with RTBCing this.
This is a huge blocker, great job @dawehner!
Comment #27
webchickNeeds a change record draft to be RTBC.
Comment #28
dawehnerI don't see that we should document more, all of that code is really deprecated already anyway
https://drupal.org/node/2203305
Comment #29
webchickWe need some before/after code of what you're supposed to do if you were depending on menu_get_item().
Comment #30
dawehnerUpdated: https://drupal.org/node/2203305/revisions/view/6951895/6952293
Comment #31
sunLooks good to me. The existing change notice(s) should indeed be sufficient for now — developers will have to re-implement all of their code for the request/response architecture anyway.
Just the DX of retrieving the current route name or route object looks a bit ugly - wondering whether we can improve that prior to release... But that's a different issue, of course.
Comment #32
alexpottmenu_get_item-2177031-25.patch no longer applies.
Comment #33
catch@sun the DX issue is currently part of #2124749: [meta] Stop using $request->attributes->get(MAGIC_KEY) as a public API, it's incredibly ugly but it's already being tracked.
Comment #34
BerdirRe-roll, only conflicted because a drupal_alter() was changed to moduleHandler in menu_get_item(), so just re-removed that part.
Comment #35
catchAdded an extra note to the change notice pointing out the request attributes stuff is provisional.
Comment #37
Berdir34: menu_get_item-2177031-34.patch queued for re-testing.
Comment #38
Sutharsan CreditAttribution: Sutharsan commentedNeeds reroll tag removed.
Comment #39
dawehnerBack to RTBC
Comment #40
webchickThe change notice wasn't exactly what I had in mind (more a before/after code comparison of D7 vs .D8). I tried to find one in the patch to use and came across this:
Which, um. Yikes! ;)
So given that people seem to use menu_get_item() for all manner of things, and given that we can't possibly ship with DX that bad, I think the way the current change notice is phrased is fine. Basically, if you needed stuff from menu_get_item() before, you now get it from $request->attributes->get(RouteObjectInterface::ROUTE_OBJECT); until we improve that in #2124749: [meta] Stop using $request->attributes->get(MAGIC_KEY) as a public API. This code snippet also highlights that we pretty desperately need #2190313: Add $EntityType::load() and loadMultiple() to simplify loading entities.
Since this currently applies, getting it in while it's hot!
Committed and pushed to 8.x. WOOT.
Comment #41
dawehnerWell this is like comparing apples and oranges to be honest.
Comment #42
xjmAdded #2124749: [meta] Stop using $request->attributes->get(MAGIC_KEY) as a public API to the change record and a comment there WRT updating it when possible.