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

Command icon 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

Anybody created an issue. See original summary.

anybody’s picture

Issue summary: View changes
Status: Active » Postponed
Issue tags: +Needs tests

I 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

anybody’s picture

Issue summary: View changes
anybody’s picture

@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.

grevil’s picture

Version: 3.0.x-dev » 4.0.x-dev
grevil’s picture

Status: Postponed » Active

Funny, 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.

grevil’s picture

Status: Active » Needs work

Also, 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.

anybody’s picture

Status: Needs work » Postponed

@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!

skaught’s picture

Status: Postponed » Closed (works as designed)

seems 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.

grevil’s picture

Status: Closed (works as designed) » Postponed

I 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?

grevil’s picture

FYI, @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.

anybody’s picture

@Grevil nice!! :)

Yes, I agree with #12! Separate issue?

anybody’s picture

Version: 4.0.x-dev » 4.1.x-dev
Status: Postponed » Active

@grevil I think we should do this now, where we ran into a weird issue with the current implementation...

skaught’s picture

Issue tags: -Needs tests

Have 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.

skaught’s picture

Status: Active » Needs review

skaught’s picture

updated from 4.1.x head

skaught’s picture

Issue summary: View changes
skaught’s picture

Issue summary: View changes
rodrigoaguilera’s picture

Any chance for a release with this fix included?

skaught’s picture

Status: Needs review » Fixed

this is now included in both 4.1.1 and 4.1.2 releases. cheers.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.