Postponed on #3348592: [regression] Language switcher block throws exception when no route is matched
Problem/Motivation
This is a follow-up on #3270979: Incorporate Drupal 9.4 core changes to getLanguageSwitchLinks to track changes in core.
I just saw #3348592: [regression] Language switcher block throws exception when no route is matched and the lines of code are very similar to the ones in this module:
- $links = $this->languageManager->getLanguageSwitchLinks($type, Url::fromRouteMatch(\Drupal::routeMatch()));
+ $route_match = \Drupal::routeMatch();
+ // If there is no route match, for example when creating blocks on 404 pages
+ // for logged-in users with big_pipe enabled using the front page instead.
+ $url = $route_match->getRouteObject() ? Url::fromRouteMatch($route_match) : Url::fromRoute('<front>');
+ $links = $this->languageManager->getLanguageSwitchLinks($type, $url);
I didn't run into it yet myself, but I guess our implementation here should be aligned to the one in core?
Did anyone experience this issue?
---
jan26/2026|skaught: linking #3353518: Frontpage (View as Page) url-alias's are different after upgrading. similarities in work.
Steps to reproduce
TBD!
Proposed resolution
Fix the implementation in this issue like core does
Remaining tasks
- Monitor the core isse
- Make changes accordingly
- Carry over tests
User interface changes
None
API changes
None
Data model changes
None
Issue fork dropdown_language-3349246
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 #3
anybodyI prepared a MR with the code from the core issue.
But we should also please carry over the tests to our tests to ensure it works as expected.
I used patch #36 as basis, let's now postpone this on the core issue and see what's the final outcome there. If anyone
Comment #4
anybodyComment #5
anybodyComment #6
anybody@Grevil could you please carry over the tests from #36 in https://www.drupal.org/project/drupal/issues/3348592 into this issue?
I think our block should just behave the same.
Comment #7
grevil commentedComment #8
grevil commentedFunny, in the added tests in https://www.drupal.org/project/drupal/issues/3348592, they implemented the tests, like they are logged in as an anonymous user, but instead, they are logged in as an "admin" account which is not completely admin, so the tests still succeed.
Comment #9
grevil commentedAlso, they check if the label of the block exists on a 403 page? That is super weird... Setting this to needs work, as it seems I do not understand the tests.
Comment #10
anybody@Grevil: If you're sure, please leave a note at the core issue.
Settings this back to PP on the core issue for now. Thanks for your work on this!
Comment #11
skaughtseems like this is not an actual error/bug report, but a related concern about how/when core may change 'something' (:
closing. no proof of damage.
Comment #12
grevil commentedI guess we should still add the tests implemented in the core issue? Since the "no route matched" problem could also appear in our module due to some regression problems in the future?
Comment #13
grevil commentedFYI, @Anybody one of the core maintainers approved my problem, mentioned in #8, I created a follow-up issue, as expected by him: #3351806: Partially refactor Language switcher block tests.
Comment #14
anybody@Grevil nice!! :)
Yes, I agree with #12! Separate issue?
Comment #15
anybody@grevil I think we should do this now, where we ran into a weird issue with the current implementation...
Comment #16
skaughtHave merged to 4.1.x dev line.
Keeping this ticket as key work line: see #3353518: Frontpage (View as Page) url-alias's are different after upgrading.
Comment #17
skaughtComment #19
skaughtupdated from 4.1.x head
Comment #20
skaughtComment #21
skaughtComment #22
rodrigoaguileraAny chance for a release with this fix included?
Comment #23
skaughtthis is now included in both 4.1.1 and 4.1.2 releases. cheers.