Problem/Motivation

On a default installation configured with at least 2 languages, if you go to a non-existing URL, such as http://site.com/nosuchpage, the language switcher has no 'is-active' class on the current language.

The error message is displayed in the correct language, but the language switcher links do not reflect the current language.

Expected behaviour:
The language switcher link for the current language should have the 'is-active' class, in the same way as it does for existing URLs.

Steps to reproduce

Proposed resolution

TBA

Remaining tasks

Patch
Add tests
Review
Commit

User interface changes

API changes

Data model changes

Release notes snippet

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

nicrodgers created an issue. See original summary.

rodrigoaguilera’s picture

It also happens when the URL has query parameters and not only to the language switcher but also for menu items that are active.

This is not nice when you use exposed filters on a view

Ralph7’s picture

Issue tags: +Dublin2016

I'm going to solve this issue at DrupalCon Dublin 2016

rodrigoaguilera’s picture

Maybe this other issue is relevant

Ralph7’s picture

I'm trying , but for the moment i didn't found the bug, it has something to do with the data-drupal-link-system-path that is empty when we are on a 404-page.(active-link.js). I'm going to try to solve this issue next week.

Ralph7’s picture

The patch that is posted on the other issue that rodrigoaguilera posted , is also going to solve this issue, so i don't know what to do know, i've tested this patch from the other issue and it solves this problem as well.

rodrigoaguilera’s picture

I feel the right thing to do un this case is to add this 404 situation to the other issue and then mark this issue as a duplicate of that one since there is more work in the other issue.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

bighappyface’s picture

@rodrigoaguilera I closed #2775651 as the query parameter issue was solved in #2968541. I think this task is good for focusing on the language switcher issues on 403/404 pages.

Anybody’s picture

Anybody’s picture

Status: Active » Needs review

Status: Needs review » Needs work

The last submitted patch, 12: language_switcher_links_is_active-2802371-12.patch, failed testing. View results

Anybody’s picture

Anybody’s picture

Status: Needs work » Closed (duplicate)
Peter Törnstrand’s picture

I am still experiencing this bug on 8.6.1. There is no .is-active class on any of the languages in the language switcher.

markdatter’s picture

I am not using BigPipe and I still have this bug on 8.7.6.

markdatter’s picture

Status: Closed (duplicate) » Active

I tested this on a fresh install of Drupal 8.7.7 on Pantheon. None of the language links have the 'is-active' class on a 404 page.

nicrodgers’s picture

Version: 8.6.x-dev » 8.9.x-dev
nicrodgers’s picture

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

quietone’s picture

I tested this on Drupal 10.1.x, standard install, with English, Italian and German. I was able to reproduce the problem.

I applied the latest patch at #2775651-41: No active language in language switcher for URL with query string and that does work. I do not know if it is the correct fix.

Anybody’s picture

Thanks @quietone, for that reason I reopened the issue you linked ([#13890435]), as it doesn't seem to have been a duplicate then. We should check both issues for a solution and if it is or should be combined fix or not.

k9606’s picture

FileSize
982 bytes

I have a multilingual site, but my background admin page uses only one language, using '$current_language_code = $this->languageManager->getCurrentLanguage()->getId(); 'will not get the exact language, So I'll change it to '$current_language_code = $this->languageManager->getCurrentLanguage(LanguageInterface::TYPE_URL)->getId();' , using the url to determine the language.

k9606’s picture

FileSize
1.11 KB

fix #30

manish.upadhyay’s picture

Hi Everyone,

Here is the updated patch for 9.5.x.

Thanks,

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

enorm’s picture

Hello and thank you for your work!

One issue for drupal 9.5 and the language switcher when 403 or 404 pages:

Result of the patch #32: Only the <a gets the is-active class BUT for a working lang-switcher you also need the parent <li as active!

  • the html should look like this:

    <ul class="links list-unstyled mb-0">
    <li hreflang="de" data-drupal-link-system-path="node/956" class="is-active">
    <a href="/de/start" class="language-link is-active" hreflang="de" data-drupal-link-system-path="node/956">Deutsch</a>
    </li><li hreflang="en" data-drupal-link-system-path="node/956">
    <a href="/en/node/956" class="language-link" hreflang="en" data-drupal-link-system-path="node/956">English</a>
    </li></ul>

    please can you have a look again at this problem for a new patch, thanks, Erich!