Comments

yesct’s picture

So we can see what we are talking about.

  /**
   * {@inheritdoc}
   */
  public function getLanguages($flags = Language::STATE_CONFIGURABLE) {
    if (!isset($this->languages)) {
      // Prepopulate the language list with the default language to keep things
      // working even if we have no configuration.
      $default = $this->getDefaultLanguage();
      $this->languages = array($default->id => $default);

      // Retrieve the config storage to list available languages.
      $prefix = 'language.entity.';
      $config_ids = $this->configFactory->listAll($prefix);

      // Instantiate languages from config objects.
      $weight = 0;
      foreach ($this->configFactory->loadMultiple($config_ids) as $config) {
        $data = $config->get();
        $langcode = $data['id'];
        // Initialize default property so callers have an easy reference and can
        // save the same object without data loss.
        $data['default'] = ($langcode == $default->id);
        $data['name'] = $data['label'];
        $this->languages[$langcode] = new Language($data);
        $weight = max(array($weight, $this->languages[$langcode]->weight));
      }

      // Add locked languages, they will be filtered later if needed.
      $this->languages += $this->getDefaultLockedLanguages($weight);

      // Sort the language list by weight.
      Language::sort($this->languages);
    }

    return parent::getLanguages($flags);
  }
yesct’s picture

Status: Active » Needs review
StatusFileSize
new1.25 KB

#2228129: Unnecessary separate config load call to load languages
changed this code but didn't update the comment.

      // Retrieve the config storage to list available languages.
      $prefix = 'language.entity.';
      $config_ids = $this->configFactory->listAll($prefix);

but we dont want to get it from config anyway.
we should try and use the entity system.

let's see if this passes. (it might not work if this is called before we have a database)

foreach (\Drupal::entityManager()->getStorage('language_entity')->loadMultiple() as $language ) {

--

if this works, we can inject the entityManager later.

---------------------------
open an separate issue for:

        $data = $language->toArray();
        $langcode = $data['id'];
        // Initialize default property so callers have an easy reference and can
        // save the same object without data loss.
        $data['default'] = ($langcode == $default->id);
        $data['name'] = $data['label'];
        $this->languages[$langcode] = new Language($data);

that logic should just be in a method like getDataObject(). then we could just:

$this->languages[$langcode] = $language->getDataObject();

Status: Needs review » Needs work

The last submitted patch, 2: 2239497.fix-getLanguages.2.patch, failed testing.

dawehner’s picture

+++ b/core/modules/language/lib/Drupal/language/ConfigurableLanguageManager.php
@@ -276,14 +276,11 @@ public function getLanguages($flags = Language::STATE_CONFIGURABLE) {
+      /** @var $language \Drupal\language\LanguageInterface */
+      foreach (\Drupal::entityManager()->getStorage('language_entity')->loadMultiple() as $language) {
+        $data = $language->toArray();
         $langcode = $data['id'];

That is kind of odd, shouldn't we just use $language->id() here? On top the obvious dependency injection stuff.

plach’s picture

We cannot use the entity manager in the language manager as the the former depends on the latter (we would introduce a circular dependency). This is the reason why we are accessing config storage directly atm. If I am missing something please let's get a real issue summary before going on with coding :)

yesct’s picture

Status: Needs work » Needs review
StatusFileSize
new534 bytes
new701 bytes
new2.18 KB

should the LanguageInterface when language module is installed be called ConfigurableLanguageInterface (note that that language manager is called ConfigurableLanguageManager).

------

thought about doing this:

diff --git a/core/modules/language/lib/Drupal/language/ConfigurableLanguageManager.php b/core/modules/language/lib/Drupal/language/ConfigurableLanguageManager.php
index b164cd5..8414ee9 100644
--- a/core/modules/language/lib/Drupal/language/ConfigurableLanguageManager.php
+++ b/core/modules/language/lib/Drupal/language/ConfigurableLanguageManager.php
@@ -17,7 +17,7 @@
 use Symfony\Component\HttpFoundation\Request;

 /**
- * Overrides default LanguageManager to provide configured languages.
+ * Overrides the Core LanguageManager to provide configured languages.
  */
 class ConfigurableLanguageManager extends LanguageManager implements ConfigurableLanguageManagerInterface {

=================

uploading these just to see what tests break and thought seeing it in code might help clarify thoughts on things.

=================

------
6

better type hint (should be no test fails)
changes type hint to indicate what it is an array of

-------
6b
there are two classes named LanguageInterface.
one is for the Core (language unaware language interface), one is for when language module is installed and language is a config entity.
name the language interface similar to the way that language manager is in the first case LanguageManager and in the second ConfigurableLanguageManager.

------
6c
options was really property values.
and name was not the label/name but the key (name)

The last submitted patch, 6: fix-2239497-6b-configurablelanguageinterface.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 6: fix-2239497-6c-namevaluekeyproperty.patch, failed testing.

tstoeckler’s picture

Status: Needs work » Needs review
StatusFileSize
new13.21 KB

Here's a patch that rolls all those patches above into one. Patch 6b failed because Language module's Language class was missing the required methods to actually implement LanguageInterface. Added those.

I only saw - after rolling the patch - that the patch 6c above renames Core's Language class' name to label. I instead renamed Language module's Language class' label to name. Sorry, didn't mean to overrule you.

I do think however, that name is a more appropriate key name - in general - for config entities but I don't feel strongly. I.e. I'm fine with reversing the rename.

plach’s picture

Title: Fix ConfigurableLanguageManager getLanguages() » Fix ConfigurableLanguageManager getLanguages()a
Status: Needs review » Needs work
Issue tags: +Needs issue summary update

Can we please have an issue summary? I am still not getting what's wrong here (see #5).

plach’s picture

Title: Fix ConfigurableLanguageManager getLanguages()a » Fix ConfigurableLanguageManager getLanguages()

The last submitted patch, 9: 2239497-9-language-cleanup.patch, failed testing.

tim.plunkett’s picture

  1. +++ b/core/lib/Drupal/Core/Config/Entity/DraggableListBuilder.php
    @@ -119,8 +119,9 @@ public function buildForm(array $form, array &$form_state) {
    -      if (isset($row['label'])) {
    -        $row['label'] = array('#markup' => $row['label']);
    +      $label_key = $this->entityType->getKey('label');
    +      if (isset($row[$label_key])) {
    +        $row[$label_key] = array('#markup' => $row[$label_key]);
           }
    

    This is a good change, but seems out of scope.

  2. +++ b/core/modules/language/lib/Drupal/language/Entity/Language.php
    @@ -80,6 +90,107 @@ class Language extends ConfigEntityBase implements LanguageInterface {
       /**
        * {@inheritdoc}
        */
    +  public function getName() {
    +    return $this->name;
    +  }
    +
    +  /**
    +   * {@inheritdoc}
    +   */
    +  public function setName($name) {
    +    $this->name = $name;
    +    return $this;
    +  }
    +
    +  /**
    +   * {@inheritdoc}
    +   */
    +  public function getId() {
    +    return $this->id;
    +  }
    +
    +  /**
    +   * {@inheritdoc}
    +   */
    +  public function setId($id) {
    +    $this->id = $id;
    +    return $this;
    +  }
    

    It's not okay to duplicate id() and label(), they are sufficient.

tstoeckler’s picture

Thanks for the review!

Re #1: That is in scope as long as we want to tackle the name -> label rename here. If you revert this the language list will fatal.

Re #2: I totally agree, but we have those methods on LanguageInterface, so don't really know what to do.

yesct’s picture

@plach yep. I'm on it. making actual separate issues with specific titles and summaries.

yesct’s picture

Title: Fix ConfigurableLanguageManager getLanguages() » [Meta] Fix ConfigurableLanguageManager getLanguages()
Issue summary: View changes

done opening sub issues.
put the list in the summary.

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.

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.

catch’s picture

Status: Needs work » Fixed

#2246721: Language class should use property 'label' to be consistent with entities is the only sub-issue remaining, so closing this as fixed, and the last one can happen when it happens.

Status: Fixed » Closed (fixed)

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