Part of #1998638: Replace almost all remaining superglobals ($_GET, $_POST, etc.) with Symfony Request object

Files that need converting are:

  • core/modules/language/language.negotiation.inc
  • core/modules/language/lib/Drupal/language/Tests/LanguageBrowserDetectionUnitTest.php
  • core/modules/language/lib/Drupal/language/Tests/LanguageUILanguageNegotiationTest.php
  • core/modules/language/lib/Drupal/language/Tests/LanguageUrlRewritingTest.php
  • core/modules/language/tests/language_test/lib/Drupal/language_test/LanguageTestManager.php
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

tyjamessmith’s picture

Assigned: Unassigned » tyjamessmith

tyjamessmith is working on this one

tyjamessmith’s picture

Assigned: tyjamessmith » Unassigned

Having some problems, feel free to take over on this one.

chertzog’s picture

Status: Active » Needs review
FileSize
7.25 KB

Lets give this a try.

kim.pepper’s picture

Status: Needs review » Needs work
+++ b/core/modules/language/language.negotiation.incundefined
@@ -86,7 +86,8 @@ function language_from_interface() {
+  $request = Drupal::request()->server->get('HTTP_ACCEPT_LANGUAGE');

Request doesn't seem the right variable name to use. How about $acceptLang ?

+++ b/core/modules/language/language.negotiation.incundefined
@@ -244,7 +245,8 @@ function language_from_session($languages) {
+  $request = Drupal::request()->query->get($param);

Again. How about $queryLang?

+++ b/core/modules/language/language.negotiation.incundefined
@@ -564,7 +566,8 @@ function language_url_rewrite_session(&$path, &$options) {
+      $query = Drupal::request()->query->get($query_param);

$query isn't the right variable name to use. How about $sessionParam?

pwieck’s picture

Status: Needs work » Needs review
FileSize
10.06 KB

Made changes as suggested by kim.pepper in comment #4 plus re-roll

Status: Needs review » Needs work

The last submitted patch, 1999388-5_replace-raw-variables-language.patch, failed testing.

pwieck’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 1999388-5_replace-raw-variables-language.patch, failed testing.

pwieck’s picture

Status: Needs work » Needs review
FileSize
10.02 KB

Since I seem to have done something wrong this is just a standard re-roll to work against without changes from #4

Status: Needs review » Needs work

The last submitted patch, 1999388-9_replace-raw-variables-language.patch, failed testing.

kim.pepper’s picture

Status: Needs work » Needs review
FileSize
4.98 KB

Looks like there was code from other issues in that last commit. This one is clean start from the current head.

Status: Needs review » Needs work

The last submitted patch, 1999388-language-request-11.patch, failed testing.

kim.pepper’s picture

Status: Needs work » Needs review
FileSize
4.98 KB

Re-roll.

marcingy’s picture

Status: Needs review » Reviewed & tested by the community

Looks good assuming comes back green

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 1999388-language-request-13.patch, failed testing.

star-szr’s picture

Issue tags: +Needs reroll

Looks like this needs a reroll.

andypost’s picture

kim.pepper’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
FileSize
1.68 KB
4.99 KB

Re-roll and use backslash for \Drupal as per #2053489: Standardize on \Drupal throughout core

Status: Needs review » Needs work
Issue tags: +Needs reroll

The last submitted patch, 1999388-language-request-18.patch, failed testing.

andypost’s picture

  1. +++ b/core/modules/language/language.negotiation.inc
    @@ -253,7 +254,8 @@ function language_from_session($languages) {
    -  if (isset($_GET[$param]) && isset($languages[$langcode = $_GET[$param]])) {
    ...
    +  if (!empty($langcode) && isset($languages[$langcode])) {
    

    No assign should happen when no $param in $_GET
    $query = \Drupal::request()->query;
    if ($query->has($param) && isset($languages[$langcode = $query->get($param)]))

  2. +++ b/core/modules/language/language.negotiation.inc
    @@ -496,7 +498,7 @@ function language_url_rewrite_session(&$path, &$options) {
    -      $query_value = isset($_GET[$query_param]) ? check_plain($_GET[$query_param]) : NULL;
    +      $query_value = check_plain(\Drupal::request()->query->get($query_param));
    

    query->has() ? check_plain() : NULL

  3. +++ b/core/modules/language/lib/Drupal/language/Tests/LanguageBrowserDetectionUnitTest.php
    @@ -154,7 +155,9 @@ function testLanguageFromBrowser() {
    -      $_SERVER['HTTP_ACCEPT_LANGUAGE'] = $accept_language;
    ...
    +      $request->server->set('HTTP_ACCEPT_LANGUAGE', $accept_language);
    +      \Drupal::getContainer()->set('request', $request);
    
    +++ b/core/modules/language/tests/language_test/lib/Drupal/language_test/LanguageTestManager.php
    @@ -20,7 +20,9 @@ class LanguageTestManager extends LanguageManager {
    -      $_SERVER['HTTP_HOST'] = $test_domain;
    ...
    +      $request->server->set('HTTP_HOST', $test_domain);
    +      \Drupal::getContainer()->set('request', $request);
    

    This could not work!

no_angel’s picture

Issue tags: -Needs reroll

removed "needs reroll" tag.

no_angel’s picture

removed "needs reroll" tag.

no_angel’s picture

Issue tags: +Needs reroll

removed "needs reroll" tag.

wouter.adem’s picture

wouter.adem’s picture

Issue tags: -Needs reroll
FileSize
1.7 KB

Created patch

wouter.adem’s picture

Status: Needs work » Needs review
Issue tags: +Needs reroll
FileSize
1.7 KB

Fix language request

kim.pepper’s picture

Thanks for this, however you are missing quite a few conversions:

language/language.negotiation.inc:84:  if (empty($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
language/language.negotiation.inc:96:  if (preg_match_all('@(?<=[, ]|^)([a-zA-Z-]+|\*)(?:;q=([0-9.]+))?(?:$|\s*,\s*)@', trim($_SERVER['HTTP_ACCEPT_LANGUAGE']
language/language.negotiation.inc:305:      $http_host= $_SERVER['HTTP_HOST'];
language/language.negotiation.inc:415:  $query = $_GET;
language/lib/Drupal/language/Tests/LanguageBrowserDetectionUnitTest.php:157:      $_SERVER['HTTP_ACCEPT_LANGUAGE'] = $accept_language;
language/lib/Drupal/language/Tests/LanguageUILanguageNegotiationTest.php:345:      // Language domain specific URL, we set the $_SERVER['HTTP_HOST'] in
language/lib/Drupal/language/Tests/LanguageUILanguageNegotiationTest.php:479:    $request = Request::create('', 'GET', array(), array(), array(), array('HTTP
language/lib/Drupal/language/Tests/LanguageUrlRewritingTest.php:128:    $request = $this->prepareRequestForGenerator(TRUE, array('SERVER_PORT' => '88'));
language/tests/language_test/lib/Drupal/language_test/Controller/LanguageTestController.php:107:    $sub_request = Request::create($base_path . '/user', 'GET
language/tests/language_test/lib/Drupal/language_test/LanguageTestManager.php:23:      $_SERVER['HTTP_HOST'] = $test_domain;

Also there are a few issues with trailing whitespace in your patch. See https://drupal.org/coding-standards#indenting for more information.

  1. +++ b/core/modules/language/language.negotiation.inc
    @@ -250,21 +250,22 @@ function language_from_user_admin(array $languages, Request $request = NULL) {
    +  ¶
    

    White space

  2. +++ b/core/modules/language/language.negotiation.inc
    @@ -250,21 +250,22 @@ function language_from_user_admin(array $languages, Request $request = NULL) {
    +  ¶
    

    Whitespace

  3. +++ b/core/modules/language/language.negotiation.inc
    @@ -250,21 +250,22 @@ function language_from_user_admin(array $languages, Request $request = NULL) {
    +  } ¶
    

    Whitespace

  4. +++ b/core/modules/language/language.negotiation.inc
    @@ -496,7 +497,13 @@ function language_url_rewrite_session(&$path, &$options) {
    +        return FALSE; ¶
    

    Whitespace

kim.pepper’s picture

Status: Needs review » Needs work

double post

herom’s picture

Status: Needs work » Needs review
FileSize
5.81 KB
6.06 KB

fixed most of #27. the remaining cases seemed to use symfony request already:

language/lib/Drupal/language/Tests/LanguageUILanguageNegotiationTest.php:479:    $request = Request::create('', 'GET', array(), array(), array(), array('HTTP
language/lib/Drupal/language/Tests/LanguageUrlRewritingTest.php:128:    $request = $this->prepareRequestForGenerator(TRUE, array('SERVER_PORT' => '88'));
language/tests/language_test/lib/Drupal/language_test/Controller/LanguageTestController.php:107:    $sub_request = Request::create($base_path . '/user', 'GET
herom’s picture

Issue tags: -Needs reroll

tag cleanup.

dawehner’s picture

Status: Needs review » Reviewed & tested by the community
+++ b/core/modules/language/language.negotiation.inc
@@ -496,7 +498,13 @@ function language_url_rewrite_session(&$path, &$options) {
+        $query_value = check_plain(\Drupal::request()->query->get($query_param));

We could just switch to String::checkPlain

penyaskito’s picture

#29: 1999388-language-request-29.patch queued for re-testing.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 1999388-language-request-29.patch, failed testing.

penyaskito’s picture

Status: Needs review » Needs work
FileSize
6.08 KB
216 bytes

Rerolled #29.

penyaskito’s picture

Status: Needs work » Needs review
FileSize
6.34 KB
1.03 KB

Switched to String::checkPlain according to #31.

dawehner’s picture

Status: Needs work » Reviewed & tested by the community

Thank you!

webchick’s picture

Status: Reviewed & tested by the community » Fixed

Committed and pushed to 8.x. Thanks!

Status: Fixed » Closed (fixed)

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