Problem/Motivation

We have a pattern where we get a Language from languageManager() and then later call getLanguageConfigOverride(). But getLanguageConfigOverride() is only for ConfigurableLanguage (managers).

for example in
ConfigLanguageOverrideWebTest::testSiteNameTranslation()

   \Drupal::languageManager()
      ->getLanguageConfigOverride($langcode, 'system.site')
      ->set('name', 'XX site name')
      ->save();

(note maybe also added in #1879930: Language selectors are not showing localized to the page language depending on how that goes in.)

Proposed resolution

use a configurable language manager when we need config things.

Remaining tasks

Contributor tasks needed
Task Novice task? Contributor instructions Complete?
Create a patch Instructions
Review patch to ensure that it fixes the issue, stays within scope, is properly documented, and follows coding standards Instructions

User interface changes

No.

API changes

No.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

YesCT’s picture

Title: use/get a ConfigurableLanguageManager later needing to call getLanguageConfigOverride() » use/get a ConfigurableLanguageManager when later needing to call getLanguageConfigOverride()
cheops90’s picture

Assigned: Unassigned » cheops90
cheops90’s picture

cheops90’s picture

Assigned: cheops90 » Unassigned
Status: Active » Needs review
Xano’s picture

+++ b/core/modules/config/src/Tests/ConfigLanguageOverrideTest.php
@@ -94,32 +94,41 @@ function testConfigLanguageOverride() {
+  /**
+   * Returns the configurable language manager.
+   *
+   * @return \Drupal\language\ConfigurableLanguageManager
+   */
+  protected function languageManager() {
+    return $this->container->get('language_manager');
+  }

Is this done just for type hinting? If so, try doing the following instead. Most IDEs can parse this.

/** @var \Drupal\language\ConfigurableLanguageManager $language_manager */
$language_manager = $this->container->get('language_manager);

cheops90’s picture

Assigned: Unassigned » cheops90

Working on it: Change the type hinting.

YesCT’s picture

Just noting that all instances of this are in tests.

cheops90’s picture

cheops90’s picture

Sorry the comment id was wrong.

cheops90’s picture

Assigned: cheops90 » Unassigned
YesCT’s picture

It is common, and helps reviewers, if when posting a new patch on an issue (that already has a patch) to include an interdiff. For instructions on creating an interdiff, see https://drupal.org/documentation/git/interdiff

YesCT’s picture

  1. +++ b/core/modules/config/src/Tests/ConfigLanguageOverrideTest.php
    @@ -8,14 +8,14 @@
    -use Drupal\simpletest\DrupalUnitTestBase;
    +use Drupal\simpletest\KernelTestBase;
    

    changes like this seem out of scope for this issue...

    I think #2351251: Replace extend of deprecated DrupalUnitTestBase with KernelTestBase in Config covers that.

  2. +++ b/core/modules/config/src/Tests/ConfigLanguageOverrideTest.php
    @@ -27,6 +27,9 @@ class ConfigLanguageOverrideTest extends DrupalUnitTestBase {
    +    $language_manager = $this->container->get('language_manager');
    +    $this->languageManager = $language_manager;
    

    is languageManager already a property we can set?

    if not, we should probably declare it.

cheops90’s picture

Patch from #7 and #9 are exactly the same - only the name is different.

Xano’s picture

That's better! Almost there :)

+++ b/core/modules/config/src/Tests/ConfigLanguageOverrideTest.php
@@ -27,6 +27,9 @@
+    /* @var \Drupal\language\ConfigurableLanguageManager $language_manager */
+    $language_manager = $this->container->get('language_manager');

This is useless, because you are assigning the language manager to a local variable without using it. The type hint should be done where you are calling methods on the object.

Are you using an IDE like PhpStorm?

YesCT’s picture

Thanks!

Dont worry if the patch number gets off by 1 or so from the comment number. that happens sometimes. :)

looks like the out of scope changes are reverted. thanks.

+++ b/core/modules/config/src/Tests/ConfigLanguageOverrideWebTest.php
@@ -41,7 +41,7 @@ function testSiteNameTranslation() {
-    \Drupal::languageManager()
+    $this->container->get('language_manager')

why like this instead of $this->languageManager like the others?

cheops90’s picture

@Xano: You are right this is useless, I removed it. Yes i use PhpStorm.

@YesCT: I used $this->container->get('language_manager') because we need only once languageManager in this class, but for the future improvements i think it is better to have a property, so i changed this too.

Thanks.

Status: Needs review » Needs work

The last submitted patch, 16: use-configurable-language-manager-2355665-16.patch, failed testing.

Xano’s picture

Yes i use PhpStorm.

Cool! Then if you write something like the following code, then right click (in PhpStorm) on getLanguageConfigOverrideStorage and select Go to > Declaration, PhpStorm will show you the method's original declaration in the interface, all thanks to the @var type hint. The other way around works too: if you don't type hint, PhpStorm will think you are calling a non-existing method and will warn you about it.

/** @var \Drupal\language\ConfigurableLanguageManagerInterface $language_manager */
$language_manager = $this->container->get('language_manager);
$language_manager->getLanguageConfigOverrideStorage('en');

As you can see, we should have type hinted on ConfigurableLanguageManagerInterface instead of ConfigurableLanguageManager (always type hint on the interface if there is one). Sorry that I put you on the wrong track!

The last submitted patch, 16: use-configurable-language-manager-2355665-16.patch, failed testing.

cheops90’s picture

Changes ConfigurableLanguageManager with ConfigurableLanguageManagerInterface.

cheops90’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 21: use-configurable-language-manager-2355665-21.patch, failed testing.

The last submitted patch, 21: use-configurable-language-manager-2355665-21.patch, failed testing.

YesCT’s picture

+++ b/core/modules/locale/src/Tests/LocaleConfigTranslationTest.php
@@ -175,7 +184,7 @@ public function testConfigTranslation() {
-    $override = \Drupal::languageManager()->getLanguageConfigOverride('xx', 'image.style.medium');
+    $override = $this->languageManager->getLanguageConfigOverride('xx', 'image.style.medium');

maybe we cannot reuse the one in the property and need to
$this->languageManager = $this->container->get('language_manager');
again. (with a comment explaining why)

(or not use a property, and just local typehint it.)

cheops90’s picture

cheops90’s picture

Status: Needs work » Needs review
YesCT’s picture

nice. it passes.

I feel like we need someone to *think* about the approach of having the properties.

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.

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.

quietone’s picture

Issue tags: +Needs reroll

Patch no longer applies cleanly.

Manuel Garcia’s picture

Assigned: Unassigned » Manuel Garcia

Rerolling...

Manuel Garcia’s picture

Assigned: Manuel Garcia » Unassigned
FileSize
14.78 KB

Manually fixed conflicts in:

  • core/tests/Drupal/KernelTests/Core/Config/ConfigLanguageOverrideTest.php
  • core/modules/config/src/Tests/ConfigLanguageOverrideWebTest.php
  • core/modules/config_translation/src/Tests/ConfigTranslationUiTest.php
  • core/modules/locale/src/Tests/LocaleConfigTranslationTest.php
Manuel Garcia’s picture

Issue tags: -Needs reroll

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

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should 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.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should 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.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should 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.

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

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.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.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.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: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should 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: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

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

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

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should 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.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should 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.

smustgrave’s picture

Version: 9.5.x-dev » 10.1.x-dev
Status: Needs review » Needs work
Issue tags: +Needs reroll, +Needs Review Queue Initiative

This issue is being reviewed by the kind folks in Slack, #needs-review-queue-initiative. We are working to keep the size of Needs Review queue [2700+ issues] to around 400 (1 month or less), following Review a patch or merge request as a guide.

This will need to be rerolled for 10.1.x

sahil.goyal’s picture

rerolling the patch against version 10.1.x and attaching the reroll_diff and few more changes are done also to get rid of PHP coding standard issues.

pooja saraah’s picture

Fixed failed commands on #48
Attached patch against Drupal 10.1.x

pooja saraah’s picture

Issue tags: -Needs reroll

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.