Problem/Motivation
<front> menu links do not receive active trail classes. Reports for this problem since D7 have been about the <li> element that wraps links, but the problem can apply to the anchor links as well, depending on the theme. This is the case with Olivero where both the <li> and <a> should receive active trail classes.
Steps to reproduce
- Install Drupal with the Standard profile and Olivero as the theme
- Visit the front page.
- Inspect the HTML of the "Home" link in the navigation menu at the top of the page.
- Verify that the
<a>has the attributedata-drupal-link-system-path="<front>".
Expected results
The menu link's <li> should have the .primary-nav__menu-item--active-trail class and the <a> should have the .primary-nav__menu-link--active-trail class.
To verify the expected behavior create a new node of any type, add it to the menu, visit the node, and then inspect the new menu link's HTML.
Actual results
Neither the <li> or <a> have the expected classes.
Proposed resolution
Update MenuActiveTrail::getActiveLink() to check whether <front> menu links should be returned as being active for the current request.
Before:

After:

Remaining tasks
- Review the MR
- Change record?
User interface changes
With the additional classes being applied to <front> links, there could be changes to the appearance of those links. These changes will be theme-specific.
API changes
The path.matcher service is added as a dependency to the menu.active_trail service.
Original reports
I've installed the bootstrap theme in a Drupal 8 site.
In the default main menu the home link is never active.
When I'm in the home page the class="is-active" won't appear.
This issue is not confined to any one theme. This appears to be a core issue.
See screenshots:
Active class missing (illustration)
Active After Applying Active Class
D7 explanation:
There is a bug with the "active-trail" class not showing up on <li> for menu items with Drupal 7.14. The problem is that "active-trail" is missing for a menu link to the front page (path "<front>"), all other links have "active-trail" just fine.
The situation is also slightly different for the horizontal primary link tabs that can be switched on from theme settings Toggle display - Main menu, than they are for the vertical navigation in the Main menu block. In the horizontal tabs the front page <li> has "active" but not "active-trail". So "active" could be used to do get around this issue for horizontal menus. But unfortunately if you want the vertical menu, there is no "active" nor "active-trail".
I verified that both "active" and "active-trail" are missing with a fresh install without any added modules on Drupal 7.4 to 7.14. The behaviour is identical with Bartik, Garland and Stark themes, as well as Zen.
The current MR fixes the bug by adding special handling for the front page when adding the active-trail class.
A better solution would be to get the 'in_active_trail' variable correctly set for links to <front>, but unfortunately I could not find out how to do that.
| Comment | File | Size | Author |
|---|---|---|---|
| #140 | interdiff.txt | 2.59 KB | dcam |
| #133 | 1578832-nr-bot.txt | 91 bytes | needs-review-queue-bot |
| #131 | 1578832-nr-bot.txt | 91 bytes | needs-review-queue-bot |
| #129 | 1578832-nr-bot.txt | 91 bytes | needs-review-queue-bot |
| #118 | 1578832-nr-bot.txt | 91 bytes | needs-review-queue-bot |
Issue fork drupal-1578832
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:


Comments
Comment #1
ttiurani commentedAttached is v2 of the patch, which is better because it does the special case handling in the place the 'in_active_trail' variable is set. With this patch caching works like it should.
Comment #2
ttiurani commentedThere seems to be a bigger problem on menu.inc than just the missing "active-trail". I stumbled on a second problem when trying to create a submodule on menu_block which hides inactive menu items. Setting 'hidden' to TRUE works great for every other link except the one(s) pointing to <front>. The variable change just doesn't stick - it turns back to FALSE right after I set it. I also don't think menu_block is to blame because it doesn't do anything to the 'hidden' variable.
I found one place which is clearly wrong in menu.inc starting from line 2468:
The problem is that none of these will find a link to <front>. When I add a fifth condition like this:
I get a little bit further, but not too much because in menu.inc there is a lot of $map = explode('/', $path); which do not work with <front> which has path 'node'.
So the bug seems to be quite a lot bigger than I anticipated.
Comment #3
ttiurani commentedI fixed my new problem with 'hidden' not sticking by using references to values (i.e. added a few ampersands). But I don't understand why the problem was only with links to the front page and not all links.
Attached is version 3 of the patch. It is against the 7.x branch and does not have tabs or whitespace problems.
The fix isn't perfect as this only adds "active-trail" to the vertical menu, not the horizontal primary links tabs.
I hope this patch will be applied or a better solution is found to new 7.x versions.
Comment #4
kristofferwiklund commentedI had the same problem. When change the menu linking for "Home" link from node/6 to the li lost it's active-trail that was used for styling. After applied the patch everything worked as it should.
Might not be the best solution to special case but I don't know if there is any other way.
Comment #6
gagarine commentedI think is why using
Fail and make the menu block disappear.
I don't understand the tests than fail but we need to add some test for this patch anyway.
Comment #7
CowTownFarmBoy commentedI have this problem and am wondering if the proposed patch is really a fix or does it fail in other places. If someone is watching this is this fixed or not?
TIA
Comment #8
ttiurani commentedAttached is a fourth version of the patch with a trivial "isset($item['link_path'])" addition that should make the patch pass those tests. I don't know how to run (or write new) tests, so unfortunately I can't say for sure. Could someone run the tests again?
I don't think this patch causes any problems and it is a fix for the problem, although not very pretty. The real issue seems to be much deeper and harder to solve as I outlined in comment #2 above.
Comment #9
gagarine commentedComment #10
ttiurani commentedUnfortunately the v2, v3 and v4 do cause problems: when you apply the patch and press "Clear all caches", and then navigate to any other page except the front page, "active-trail" doesn't show up. And if you do go to the front page after clearing caches and get "active-trail" to show up, it stays on when you navigate to the user page, which I don't think it should. I also have managed to get "active-trail" to disappear a few times when I went back and forth to the user page and menu.
So it seems that _menu_tree_data() is too complex a method for a quick fix.
The first version of the patch, where the special casing is done in menu_tree_output() is the most stable, but doesn't fix the problem in modules such as menu_block which override that method.
So I guess the only thing to do is to fix this properly. I need to get this to work immediately so I will just do a quick fix in Menu Block.
Comment #11
aliyayasir commentedStill have this issue in drupal 7.16
Comment #12
drewschmaltz commentedI'm also not getting children of in the secondary menu - maybe this is related. Sort of shocked here. Fighting this and the fact that "active" never shows up for "my account".
Comment #13
matulis commentedWorkaround for the
<front>linkshttp://drupal.org/node/1571058#comment-6788662
Comment #14
jenlamptonPatch in #8 works great, thanks @ttiurani!
Comment #15
David_Rothstein commentedAs far I can tell, this would exist in Drupal 8 too? Also, #10 indicates there are problems with the patch...
Comment #16
David_Rothstein commentedSee also possible related issue or duplicate: #1063278: Menu item linked to <front> doesn't know its active
Comment #17
vortex9 commentedI applied the patch v4 to 7.19, but it does't work
Comment #18
ttiurani commentedAs I pointed out in #10, only the first version of the patch works, but it is a hack. I ended up using Menu Block to get around this problem.
Comment #19
vortex9 commentedI'm using Nice menu. I can't combine Nice menu with Menu Block :(
Add this http://drupal.org/node/1571058#comment-6788662
Its works!
Comment #20
jenlamptonAlright, this takes the approach from the comment mentioned above and adds the active class attribute in the theme function - getting around the caching issues caused by the previous approach.
Attached patches for D8, and D7.
Comment #21
zhangx1a0 commentedpatch #20 works great!
Comment #22
Screenack commentedPatch core at your own risk. Until core is updated appropriately, I like this solution better: http://drupal.org/node/1571058#comment-6788662
Comment #23
vortex9 commentedupdate to 7.22 and apply #20 - cool!
Comment #24
David_Rothstein commentedComment #25
peyman_6000 commentedfix_missing_active_trail.patch queued for re-testing.
Comment #26
vortex9 commented#20: core-fix_missing_active_trail-1578832-20.patch queued for re-testing.
Comment #27
gappleAs per #2126319: <strong>Strip HTML tags for issue titles in listings</strong>, HTML tags in issue titles are not entirely escaped on the listing page, which is breaking validity.
(and has been preventing http://drupalreleasedate.com from being able to parse the page in order to get a count of issues for some time now)
Comment #28
jenlamptonPatch in #20 still applies cleanly to 7.32
Comment #29
jenlamptonadding tag back.
Comment #32
jenlamptonPatch in #20 still applies cleanly to 7.39
Comment #34
toomanypets commentedComment #35
toomanypets commentedThis work-around almost works with Drupal 8.1.8...
/admin/structure/menu/link/standard.front_page/edit
/admin/structure/menu/manage/main/add?destination=/admin/structure/menu/manage/main
Menu link title: Home
Link: /node
But /node is shown when you hover over the Home link, and /node will be exposed to search engines... neither of these are desirable.
I believe this is another symptom of the
<front>or/nodeor/mess.Comment #37
alisonHarrumph, any chance of a fix getting into 8.x soon, or a functional patch for D8? :( :(
(Yes I know I'm not helping....... I'll look now and see if I feel capable enough to do something to help instead of just whining........)
Comment #38
alisonErrrrr never mind! Apparently it "just works," we just had a config wrong (someone added the menu link via menu admin UI, and linked to the front page or node/1 -- as soon as I removed that link and instead edited node #1 and added the menu link from in there, it worked fine/no troubles).
Sorry and never mind and thanks!
Comment #40
alsator commentedUsing superfish module has resolved it for me
Comment #43
legolasboI tried fixing this in the part that builds the menu tree, but time constraints on my project force me to take the template_preprocess_menu() route.
Comment #44
legolasboShouldn't have changed the version. Sorry
Comment #46
legolasboPrevious patch caused fatal errors with external urls,
Comment #48
jenlamptonPatch in #34 still applies cleanly to Drupal 7.59.
Comment #50
lamp5I can confirm that code from #46 works well. I use it as my theme preprocess until it will be tested and committed to core.
Comment #51
martijn de witTried patch #48 as described in #50
When I visit the frontpage. Not only the frontpage link < li > is in the active-trail. But also all siblings.
Comment #52
pdenooijer commentedImproved patch 46:
instanceof Urlchecks to make sure no WSOD occur.Comment #53
pdenooijer commentedComment #54
lukassykora commentedThis version is working for me.
Comment #56
pdenooijer commentedSorry lukassykora but your patch is just a less defensive version of my patch and it failed the tests, so changing it back to review on my patch.
Comment #57
mishac commentedThe patch in 52 seems to make *all* links on the front page have the "active-trail" class instead of just links to the front page :(
Comment #58
adamtong commentedi found a work-around for this issue, just create a disabled menu item for the true home page (e.g. /node/1) under home link.
Comment #59
lpeabody commentedThe patch in #52 applied cleanly on 8.7.8 and it worked for me. I cannot confirm the side effect mentioned in #57 - every menu link looks like it has the appropriate classes and only links representing the current page show as is-active.
Comment #60
martijn de witAdded an automated test for 8.8 and 8.9 to the patch #52.
Hopefully this can be committed soon.
Comment #61
alexpottI think #60 is missing a patch. This issue needs an automated test in order to be committed.
Comment #62
joseph.olstad@Martijn de Wit, can you please dig up the automated test that you wrote and somehow failed to upload to this issue?
Comment #63
joseph.olstadpatch #52 still works great! Just tested it manually.
@Martijn de Wit, could you please find that automated test you wrote 5 months ago and somehow failed to upload?
Comment #64
joseph.olstadHad to reroll patch 52 for Drupal 9.0.x
So to simplify I up uploading two patches, one for 9.0.x and the other for 8.9.x/8.8.x/8.7.x
patch 8 is for D7, still applies cleanly, I'll split that into a new seperate D7 issue
Comment #65
joseph.olstadFor the D7 issue:
#3119861: [D7] Class active-trail not added to li element when linking to front page
Comment #66
joseph.olstadActive class missing (illustration)
Active After Applying Active Class
Comment #67
joseph.olstadComment #68
martijn de witno, sry
Comment #69
joseph.olstadafter a few weeks of testing, patch 64 has regressions, it caused more than one link to have the active trail classes on the same page
I backed off the patch and removed it from our build.
As a workaround , our links for both of our languages are on one menu, internal links are fine, for external links we're using a workaround with css using a contrib module which allows specifying a class to the link. There's other ways to work around the external links I've used this method and another is to use also html lang attribute then the a element css selector on the href attribute based on a pattern to hide or show the opposite language external link.
Using one menu for both languages our active trail works fine. I'm not sure about the site default page issue haven't noticed it yet.
Anyhow, the patch 64 was derived from the others and I backed it off, no longer using it, doing a workaround instead.
previously we had menus for the default language and another different menu with another language and used block visibility on language for this, but this method proved to break the active trail for the 'other' language. So workaround is to use one menu for both our languages as I mentioned in this comment.
hope this helps.
Comment #70
xjmWe should fix this bug in D8 too, so filing against 8.8.x (which is the current bugfix support branch). The issue will be automatically updated to 8.9.x after the last 8.8.x bugfix release. Thanks for juggling all the different patches for this fix!
Comment #72
nicholasthompsonJust applied patch 64 before reading comment 69... Can confirm 64 adds the in_active_trail too generously 😉
Comment #73
nicholasthompsonAhh so the problem for me is that the frontpage is a node (node/1). So:
$validHomepageRoutes = ['', $homepageUrl->getRouteName()];
This contains and "entity.node.canonical" so every menu item that is front or a node gets flagged.
Comment #74
joseph.olstadThis being not fixed leaves us wanting to fix this.
challenges:
rather than do these workarounds, we would like to add a menu block per language allowing us to have unique weights for menu links and not have to fuss about external link translation for the url which is not always the same , often each language has an external link equivalient but for whatever reason (maybe explained above) this breaks the active-trail likely due to the bug mentionned above.
Currently we're working around this issue by using the https://www.drupal.org/project/menu_link_attributes menu_link_attributes module to provide a class attribute for links. We put this together on the same menu for both languages instead of a menu for each language (weights is another issue)
We want to make sure to maintain active trail functionality in both languages, there's the active class that indicates that the current link is what we're presently on, this is part of the menu functionality we didn't want to break and also keyboard navigation, due to wanting active trail to work in both languages we used one menu for two languages instead of two menus due to us wanting to work with what works for active trail menu links, one menu, links of all languages, internal links are no problem as they have a label that is translated and the internal link is automatically generated however external links like this one required a change in implementation to both the javascript and css, so we put a eng-only class on the english link that puts display: none on for the english link in french and a fra-only class on the french external link and there's another class attribute also, Drupal will render both links , css hides the other language external link, HOWEVER this does not fully allow wcag compliance in my recent wcag audits, SO we wrote some javascript to remove the other language link after the page is ready before the user navigates with the keyboard so when the menu link is configured as such using the specified class the javascript will also kick in and actually remove the other language link from the front end display which allows keyboard navigation to function correctly (wcag compliance, keyboard navigation is required). So the page renders, the css hides the other language link so it is never visible, then the javascript kicks in and removes the other language link from the html and thus we are able to pass wcag keyboard navigation and use the keyboard and tab key as expected.
it could be easier!
Comment #75
lpeabody commentedI'm going to try and address this in MenuTreeStorage::loadByRoute. Reasoning for this:
Assume you have the front page set as /node/1234. Also assume you have a menu named
mainand that menu has a single link which uses<front>.Given the above, currently if you were to attempt to invoke
MenuTreeStorage::loadByRoute('entity.node.canonical', ['node' => 1234], 'main'), you would get no results, even though that node is the front page.I think the best course of action here is for the service to be aware of whether or not the passed route name/parameters represents the front page, and if it does then make the 'route_name' portion of the query part of an OR condition, where that condition also checks for
<front>.EDIT: I realize I didn't explain why this actually solves this issue. Which menu items get flagged as active comes from Drupal's
menu.active_trailservice. That service uses the current page's route match to get the page's route name and parameters, and invokes the aforementioned function to get the active link, and then it gets that links parents to build the rest of the trail.The current page's route match will never, ever be the
<front>route, it will always be what the actual route object is for that page in the system. So, we have to help MenuTreeStorage understand what the front page is.Comment #77
lpeabody commentedOpened a MR with a somewhat rough implementation of where I think this needs to go. My local testing has been positive so far, and it appears to fix this issue in its entirety. I am not sure what kind of performance hit this adds. Still needs automated tests.
Comment #78
lpeabody commentedYeah don't use the above branch for anything yet, lots of failed tests relating to cyclic dependencies, I'm hoping to be able to dig into it later today.
Comment #79
pfrenssenThis is the circular reference error thrown that is mentioned by @Ipeabody:
Comment #82
neograph734I've previously also noticed some weird behavior in the active trail when the homepage contained a query string (example.org?foo=bar). Weirdest that I fgured out is that there is also JavaScript involved. If you disable Javascript the front page never gets an active trail class.
Linking as relevant issues.
Comment #86
dcam commentedThe following workaround code was adapted from #64. It corrects the problem of flagging all routes of the same name by also comparing the route parameters.
Comment #89
dcam commentedI disagree with the approach in the previous MR that made
MenuTreeStorage::loadByRoute()load front page routes. It violates the single responsibility principle and will result in unexpected behavior for calling code.My own approach is to add a check for the front page to the
menu.active_trailservice'sgetActiveLink()function. That function is responsible for determining whether a menu is in the trail or not.<front>is effectively an alias for the front page route. So if anything needs to compensate for these non-standard<front>links, that seems like the most appropriate function to do it.That said, I was a little confused at first because the docblock for
MenuActiveTrailInterface::getActiveLink()is misleading:There is no "given route" because you don't pass a route to the function. Instead, it gets the current route from the
current_route_matchservice. There's some code smell going on here. I assert that the docblock in the interface is incorrect and needs to be changed. I updated it to say that it looks for a menu link for the currently active route, although even that can't be guaranteed by the interface. There's an argument that the docblock change should be a separate issue, but since we're altering the behavior of this function to look for "alias" links that should be active for the current route, then I argue that it's an appropriate change for this issue.The lack of route injection for the function also made the test harder to write. I tried to make a kernel test, but eventually punted on that and made a functional test that checks for Olivero's active trail class. I don't like it, but I couldn't figure out how to do it any other way. If someone has suggestions, please let me know.
Comment #92
oily commentedComment #93
oily commented@dcam There seems to be a test has got broken. Line 126 of SystemMenuBlockTest.php seems root of the problem?:
Comment #94
oily commentedAdded tags including an issue summary update: the current issue summary dates back to Drupal 7. Before and after screenshots for Drupal 11 are needed. The steps to reproduce could be simplified.
Another thing is, it states in the current Issue summary:
This should be investigated.
There is now a failing test so test coverage is in place. There is currently one broken kernel test that needs to be fixed before the issue can be reviewed.
Comment #95
oily commentedComment #96
oily commentedHave updated the Issue summary so it makes more sense in relation to Drupal 11.
There is more work to do. The screenshots need to be updated for Drupal 11 and any discrepancies with the existing D8 and D7 sections in the issue summary can be rectified.
To improve readability, the latest issue summary template should be used.
Comment #97
dcam commentedYeah. I saw that. But it was well past quitting time for the day, so I haven't tried to debug it. That's why I didn't set the issue status to Needs Review. Just from glancing at the backtrace it looked like the change to the service either broke the system menu block or maybe just the test. I'm not sure which.
Comment #98
oily commented@dcam Great work. This is a long-standing bug!
Comment #99
dcam commentedSystemMenuBlockTestwas failing because it mocks all the routes. But when the menu links were being built for the block they went through thepath.matcherservice which checked for the existence of the routes. Since they didn't actually exist it threw exceptions. I mocked the service to fix the test.Comment #100
dcam commentedComment #101
oily commented@dcam Great!
Comment #102
dcam commentedIssue summary update
Comment #103
dcam commentedComment #104
smustgrave commentedLeft some comments on MR
Thanks
Comment #105
dcam commentedA kernel test needs to be created to verify the fix.
Comment #107
vidorado commentedI’ve contributed my two cents and implemented it as a unit test, as the necessary mocking was straightforward, just like in the existing
MenuActiveTrailTestunit test.I've tested the
MenuActiveTrail::getActiveLink()method, which should return the first<front>route menu link when the current page is the front page and corresponds to a route without its "own" links. This scenario occurs in a default fresh Drupal installation, where the home page is theview.frontpage.page_1route and the main navigation menu has only a "Home" link provided by thesystemcore module for the route<front>.Comment #108
smustgrave commentedSuper close, just 1 more comment.
Comment #109
vidorado commentedThat was a hard one! :)
Comment #110
smustgrave commentedThanks! just needs a rebase now and think it's good to move up
Comment #111
vidorado commentedOops! I'm sorry, I was so focused on the test pipeline passing that I overlooked the merge conflicts :)
Thanks for the review!
Comment #112
smustgrave commentedThanks, believe this is good to go now.
Comment #113
needs-review-queue-bot commentedThe 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.
Comment #114
dcam commentedUpdated the target branch. Restoring RTBC status.
Comment #115
oily commented@dcam just re-ran the one failing test. Test that failed, error mentioned CKeditor. Cant see the connection?..
Comment #116
oily commentedPipeline green, test only test fails as it should.
Comment #117
dcam commentedThanks @oily. I forgot to check on the test results after I rebased the MR to make certain it would still apply after all the recent commits to Core.
Comment #118
needs-review-queue-bot commentedThe 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.
Comment #119
joseph.olstadComment #120
dcam commentedI'm going to have to iteratively update the StandardPerformanceTest to account for the changes to the cache as a result of the bug fix. Because for some reason my local environment doesn't want to run FunctionalJavascript tests today so that I can do this in one commit.
Comment #121
vidorado commentedI could help you out if you want. Let me know here or contact me in slack :)
Comment #122
dcam commentedAll the tests are green again. I'm setting this back to Needs Review instead of RTBC only because this wasn't a simple rebase this time. I had to make adjustments to the expected values in the StandardPerformanceTest. They're probably innocuous, but someone should look them over.
Comment #123
vidorado commentedThe new numbers look reasonable to me
Comment #124
dcam commentedI rebased again due to a merge conflict caused by this morning's commits to Core. This was an easier rebase than the last one, so I'm leaving it at RTBC.
Comment #125
drupgirl commentedMarking as needs work, as this patch does not apply to 10.4.
Comment #126
vidorado commentedThat's normal @drupgirl, it has to apply to the last major development branch (11.x in this case)
You can make a backport and publish it here as a patch, for others.
Comment #127
vidorado commentedComment #128
dcam commentedSorry for all the rebasing spam. I've been trying to keep this up to date despite all of the other recent commits. Practically every change to the performance test forces a rebase and update of this MR.
Comment #129
needs-review-queue-bot commentedThe 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.
Comment #130
dcam commentedI rebased the MR against 11.x again. Restoring RTBC status.
Comment #131
needs-review-queue-bot commentedThe 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.
Comment #132
dcam commentedRebased again.
Comment #133
needs-review-queue-bot commentedThe 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.
Comment #134
dcam commentedRebased. Again. Restoring RTBC.
Comment #135
nod_Looks good to me but outside my scope
Comment #136
longwaveLooks good to me too but we need to do the deprecation dance in the constructor because there are existing contrib modules that extend this service.
Comment #137
dcam commentedI responded to all MR feedback and made the suggested changes. I don't have a good explanation for the typehint removals though.
Comment #138
catchOh I get it now - CacheCollector doesn't type hint the class, so they can't be constructor property promoted and also type hinted.
In this case what we need to do is remove the constructor property promotion, and add back the type hints.
Needs work for that but I think this is ready otherwise.
Comment #139
oily commentedRecent commits trying to achieve #138. I think need to add back in 2 of the params following the same typehint-no-constructor-property-promotion pattern. Also need to figure out which params to put in parent and which to put in the current class constructors.
Comment #140
dcam commentedI'm daring to self-RTBC this because:
But since there are a lot of commits that have happened since #138 I figure that a good, old-fashioned interdiff wouldn't go amiss.
Comment #141
dcam commentedThis needed yet another rebase due to performance test changes.
Comment #142
larowlanLeft a comment on the MR regarding the deprecation link.
There's also a performance impact here, I've pinged catch about whether we need to fix that here or in a followup.
Comment #143
larowlanDiscussed with @catch and he was ok with adding the 'load multiple' equivalents in a follow up
Can we get that issue added and update the code in MenuActiveTrail service to add a @todo pointing to the new issue?
That plus a change record (and update the link) and this can go back to RTBC, self RTBC is fine as its only comment/deprecation changes.
Thanks!
Comment #144
dcam commentedFollow-up issue: https://www.drupal.org/project/drupal/issues/3523497
Change record: https://www.drupal.org/node/3523495
Thanks again!
Comment #146
larowlanCommitted to 11.x
Published the change record.
Whilst this is a bug it is not eligible for backport because of the constructor BC change.
Thanks all, great to see this one finally resolved!
Comment #148
berdirPSA: This broke menu_trail_by_path due to the constructor changes in a way that confused me a bit.
What that module does is alter the service like this:
So it gets the new argument added here but then its constructor doesn't expect that.
Don't see how this could do anything different, turns out that's a bad pattern for extending a constructor. Will switch to setters or autowire in #3524724: MenuActiveTrail::__construct() changes in Drupal 11.2 conflict with service alteration
Comment #149
quietone commentedThe change record for this issue is a repeat of the deprecation message. It should include an example of before and after as well.
Comment #151
xjmWere #148 and #149 addressed?
Comment #152
quietone commentedAssigning to myself to followup in a week or so
Comment #153
dcam commentedSince I originally authored the CR I took responsibility for updating it with the before/after examples. But I'm going to leave the issue metadata the same so @quietone can review my changes and address #148 if necessary.
Comment #154
quietone commented@dcam, thanks for updating the CR. Providing extra detail, even for this straightforward deprecation, makes it clear what needs to be done.