Problem/Motivation

When using the "Language from the URL" language detection, the "is-active" CSS class is not added to the li tag of the active language in the language switcher block when the request contains query parameters (for instance from a pager).

Proposed resolution

Add the query parameters to the language switcher links returned by LanguageNegotiationUrl::getLanguageSwitchLinks().

Remaining tasks

Review and probably write a test.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

morenstrat created an issue. See original summary.

morenstrat’s picture

Status: Active » Needs review
FileSize
1.08 KB

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Ante890’s picture

Thank you for the patch . Should be implemented in core.

morenstrat’s picture

Updated Patch for 8.1.x-dev

Ante890’s picture

Status: Needs review » Reviewed & tested by the community

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 5: 2689607-5.patch, failed testing.

Ante890’s picture

Status: Needs work » Reviewed & tested by the community
alexpott’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs tests

Let's test this.

+++ b/core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationUrl.php
@@ -191,7 +191,9 @@ public function processOutbound($path, &$options = array(), Request $request = N
-    $links = array();
+    $links = [];
+    $query = [];

Let's not do conversion to short syntax in this issue.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Ante890’s picture

Ante890’s picture

Status: Needs work » Needs review
Ante890’s picture

Status: Needs review » Reviewed & tested by the community
alexpott’s picture

Status: Reviewed & tested by the community » Needs work

Still needs an automated test.

Ante890’s picture

I added a query string to doTestLanguageBlockAnonymous test function. Any feedback is welcome.

Ante890’s picture

Status: Needs work » Needs review
Ante890’s picture

Status: Needs review » Reviewed & tested by the community
amit.drupal’s picture

Review patch #15 its looking good.it is nicely working

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: -Needs tests
  1. index a1d4da4..04526bb 100644
    --- a/core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationUrl.php
    
    @@ -192,6 +192,8 @@ public function processOutbound($path, &$options = array(), Request $request = N
    +    $query = array();
    +    parse_str($request->getQueryString(), $query);
    

    I think we can just do $query = $request->query->all(); instead of this.

  2. +++ b/core/modules/language/src/Tests/LanguageSwitchingTest.php
    @@ -118,8 +118,10 @@ protected function doTestLanguageBlockAuthenticated($block_label) {
    +    $this->drupalGet('',$options);
    

    Need a space between , and $options - but I would just do this like this:
    $this->drupalGet('', ['query' => ['foo' => 'bar']]);

    Also I would detail what the testing purpose is - ie. to ensure that the active class is added correctly if query params are present.

  3. I confirmed the test without the fix produces fails - but it is always good to upload a test-only patch to prove this.
morenstrat’s picture

Test-only patch. This should fail.

morenstrat’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 20: 2689607-20.patch, failed testing.

morenstrat’s picture

An the complete patch with fix and test.

Ante890’s picture

Great work morenstrat. Now I think we have a patch that should be approved.

Ante890’s picture

Status: Needs review » Reviewed & tested by the community

  • catch committed 4e5cb3f on 8.3.x
    Issue #2689607 by morenstrat, Ante890: Language from URL negotiator does...

  • catch committed ae0c087 on 8.2.x
    Issue #2689607 by morenstrat, Ante890: Language from URL negotiator does...
catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed/pushed to 8.3.x and cherry-picked to 8.2.x. Thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.