[regression] Language switcher block returns links to node on the frontpage

Created on 31 March 2023, over 1 year ago
Updated 20 November 2023, about 1 year ago


Problem/Motivation

After upgrading to 9.5.7 the Language switcher block doesn't return the route name if the node was added as a front page on the Basic site settings. So on the frontpage the link will be always entity.node.canonical not .

Steps to reproduce

  1. Install all of the Multilingual modules
  2. Add another language
  3. Enable Article and/or Basic page for content translation
  4. On the Detection and selection page enable Path prefix for the language detection and add prefixes
  5. Place the Language switcher content block
  6. Add a piece of content
  7. On the Basic site settings set the newly created page as a frontpage.
  8. View the frontpage. The language switcher block is shown.
  9. Check links from the source of the language switcher block using Chrome Inspect. Instead of leading to "/" and "/{language_prefix}" the link will lead to the node page (/node/nodeID)

Proposed resolution

Fix

Fix is in patch #32
MR can be closed

The issue is related to the Drupal\language\Plugin\Block\LanguageBlock build() function on this code:

    // 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);

Adding here a check if the current page is a frontpage solves the issue:

     if ($this->pathMatcher->isFrontPage() || !$route_match->getRouteObject()) {
      // We are skipping the route match on both 404 and front page.
      // Example: If on front page, there is no route match like when creating
      // blocks on 404 pages for logged-in users with big_pipe enabled, use the
      // front page.
      $url = Url::fromRoute('<front>');
    }
    else {
      $url = Url::fromRouteMatch($route_match);
    }
    $links = $this->languageManager->getLanguageSwitchLinks($type, $url);
๐Ÿ› Bug report
Status

Fixed

Version

10.2 โœจ

Component
Language systemย  โ†’

Last updated about 19 hours ago

  • Maintained by
  • ๐Ÿ‡ฉ๐Ÿ‡ชGermany @sun
Created by

๐Ÿ‡บ๐Ÿ‡ฆUkraine dburiak

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024