Spawning an issue from

#2226533: Changes to the Language class due to the LanguageInterface (followup)

extracting all the getName() changes, for example

- $default->name = t("Site's default language (@lang_name)", array('@lang_name' => $default->name));
+ $default->setName(t("Site's default language (@lang_name)", array('@lang_name' => $default->getName())));

CommentFileSizeAuthor
#53 interdiff.2341341.50.53.txt1.6 KBYesCT
#53 2341341.53.patch45.21 KBYesCT
#50 interdiff.2341341.49.50.txt910 bytesYesCT
#50 2341341.50.patch45.25 KBYesCT
#49 2341341-diff-46-49.txt1.05 KBvijaycs85
#49 2341341-language-name-49.patch45.1 KBvijaycs85
#47 2341341-diff-46-47.txt1.05 KBvijaycs85
#47 2341341-language-name-47.patch45.1 KBvijaycs85
#46 2341341.46.patch45.07 KBYesCT
#46 interdiff.2341341.44.46.txt677 bytesYesCT
#44 2341341.44.patch45.06 KBYesCT
#44 interdiff.2341341.37.44.txt3.17 KBYesCT
#37 interdiff-34-37.txt606 bytesmartin107
#37 name-2341341.37.patch42.93 KBmartin107
#37 interdiff-34-37.txt606 bytesmartin107
#37 name-2341341.37.patch42.93 KBmartin107
#34 name-2341341.34.patch43.52 KBmartin107
#30 interdiff-26-30.txt4.4 KBmartin107
#30 name-2341341.30.patch43.94 KBmartin107
#27 interdiff-23-26.txt1.58 KBmartin107
#26 name-2341341.26.patch39.95 KBmartin107
#26 interdiff-23.26.txt825 bytesmartin107
#23 interdiff-20-23.txt1.16 KBmartin107
#23 name-2341341.23.patch39.91 KBmartin107
#20 2341341.20.patch39.59 KBYesCT
#17 interdiff.15.17.txt647 bytesYesCT
#17 2341341.17.patch39.59 KBYesCT
#15 interdiff.2341341.14.15.txt404 bytesYesCT
#15 2341341.15.patch38.96 KBYesCT
#14 interdiff.2341341.11.14.txt1.22 KBYesCT
#14 2341341.14.patch38.56 KBYesCT
#11 2341341-11.patch38.29 KBYesCT
#11 2341341-11.patch38.29 KBYesCT
#5 reroll-getName-2341341-5.patch38.17 KBfran seva
#3 interdiff-1-3.txt1.34 KBmartin107
#3 getName-2341341-3.patch37.82 KBmartin107
#1 getName-2341341-1.patch37.83 KBmartin107
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

martin107’s picture

Assigned: martin107 » Unassigned
Status: Active » Needs review
FileSize
37.83 KB

The original patch 263.3Kbytes stripped down to 38.8Kbytes.

Which suggests it should not need to be rerolled daily.

Lets see what testbot makes of it.

Status: Needs review » Needs work

The last submitted patch, 1: getName-2341341-1.patch, failed testing.

martin107’s picture

Assigned: Unassigned » martin107
Status: Needs work » Needs review
FileSize
37.82 KB
1.34 KB

Despite my efforts to stamp it out, some changes to getName() also contained conversions of ->locked to ->isLocked()

Long story short some isLocked functions sneaked in, and caused problems.

PS I will sit on this until it goes green

martin107’s picture

Assigned: martin107 » Unassigned

green :)

fran seva’s picture

Attach reroll

martin107’s picture

Thanks ... I've had a visual scan of the file....

all looks good nothing out of scope, everything appropriate.

YesCT’s picture

I'm looking at this now too. :)

YesCT’s picture

Status: Needs review » Needs work

This needs to change name on Language.

I thought maybe this issue might also need to set label property on ConfigurableLanguage to protected... but. Maybe we should do this one as two different issues. ...
Or maybe we should ... but the question is, what method would we use? the label() or getName()?

YesCT’s picture

Issue tags: +Amsterdam2014

I am about to reroll this.

Gábor Hojtsy’s picture

Title: Language module followup - separate out the getName() changes » Change public 'name' property access on languages to getName()
Issue tags: +D8MI, +sprint, +language-base

Better title, tags.

YesCT’s picture

Status: Needs work » Needs review
FileSize
38.29 KB
38.29 KB

(just a small note to remind myself)

using a var (and/or a type hint)
for

      foreach ($this->container->get('language_manager')->getLanguages($flags) as $langcode => $language) {
        $options[$langcode] = $language->isLocked() ? t('- @name -', array('@name' => $language->name)) : $language->getName();
      }

in LanguageSelectElementTest
would help

---
just a reroll.

next let's see what the bot says,
and also make the properties protected.

The last submitted patch, 11: 2341341-11.patch, failed testing.

YesCT’s picture

accidentally uploaded same one twice. I canceled one of them.

YesCT’s picture

oh, looks like I missed one. wonder why it didn't fail. maybe we are missing test coverage for it is a locked language.

at first I did

+++ b/core/modules/system/src/Tests/Form/LanguageSelectElementTest.php
@@ -55,8 +55,10 @@ function testLanguageSelectElementOptions() {
     foreach ($ids as $id => $flags) {
       $this->assertField($id, format_string('The @id field was found on the page.', array('@id' => $id)));
       $options = array();
-      foreach ($this->container->get('language_manager')->getLanguages($flags) as $langcode => $language) {
-        $options[$langcode] = $language->isLocked() ? t('- @name -', array('@name' => $language->name)) : $language->getName();
+      /* @var $languages \Drupal\Core\Language\LanguageInterface[] */
+      $languages = $this->container->get('language_manager')->getLanguages($flags);
+      foreach ($languages as $langcode => $language) {
+        $options[$langcode] = $language->isLocked() ? t('- @name -', array('@name' => $language->getName())) : $language->getName();
       }
       $this->_testLanguageSelectElementOptions($id, $options);
     }

but get languages should know it is returning languages... so maybe a bit different...

yeah, I think this is better:

-      foreach ($this->container->get('language_manager')->getLanguages($flags) as $langcode => $language) {
-        $options[$langcode] = $language->isLocked() ? t('- @name -', array('@name' => $language->name)) : $language->getName();
+      /* @var $language_manager \Drupal\Core\Language\LanguageManagerInterface */
+      $language_manager = $this->container->get('language_manager');
+      foreach ($language_manager->getLanguages($flags) as $langcode => $language) {
+        $options[$langcode] = $language->isLocked() ? t('- @name -', array('@name' => $language->getName())) : $language->getName();

will do the protected next.

YesCT’s picture

FileSize
38.96 KB
404 bytes

and making name protected on Language.

need to think about what to do with ConfigureableLanguage.

Status: Needs review » Needs work

The last submitted patch, 15: 2341341.15.patch, failed testing.

YesCT’s picture

Status: Needs work » Needs review
FileSize
39.59 KB
647 bytes

1.
#2341313: Convert all t() calls to $this->t() in views. added a ->name direct call. found it and fixed it to getName().

2.
LanguageManager tries to rename a language object... hm.

    // Add the site's default language if flagged as allowed value.
    if ($flags & LanguageInterface::STATE_SITE_DEFAULT) {
      $default = isset($default) ? $default : $this->getDefaultLanguage();
      // Rename the default language. But we do not want to do this globally,
      // if we're acting on a global object, so clone the object first.
      $default = clone $default;
      $default->name = $this->t("Site's default language (@lang_name)", array('@lang_name' => $default->getName()));
      $filtered_languages[LanguageInterface::LANGCODE_SITE_DEFAULT] = $default;
    }

should probably construct a new one with the new name?

3.
ContentTranslationSettingsTest

    $field_override = BaseFieldOverride::loadByName('entity_test_mul', 'entity_test_mul', 'name');

@penyaskito pointed out this might need to provide an extra method with a callback and not the property name.

4.
I'm not sure how to track down things like: Call to a member function on a non-object

Sample:
"Fatal error: Call to a member function getOption() on a non-object in /var/lib/drupaltestbot/sites/default/files/checkout/core/modules/views_ui/src/Tests/DisplayCRUDTest.php on line 141
FATAL Drupal\views_ui\Tests\DisplayCRUDTest: test runner returned a non-zero error code (255)."

maybe run the test locally and look at the trace?

Status: Needs review » Needs work

The last submitted patch, 17: 2341341.17.patch, failed testing.

YesCT’s picture

I thought maybe I could go back to a passing patch in #2226533: Changes to the Language class due to the LanguageInterface (followup) and see how this differed... but that one didn't make $name protected. :/

and good news ;) needs a reroll cause #2304403: Convert language:weight into a protected property

YesCT’s picture

Status: Needs work » Needs review
FileSize
39.59 KB

just the reroll.

Status: Needs review » Needs work

The last submitted patch, 20: 2341341.20.patch, failed testing.

martin107’s picture

Assigned: Unassigned » martin107

I am taking a look at this now ....

martin107’s picture

Status: Needs work » Needs review
FileSize
39.91 KB
1.16 KB

So here are some notes as I worked along....this is my fix for 17.2 making FilterEqualityTest.php pass.

Cloning a language and then overriding is no longer possible, as by design coders are constrained to only setting things up at construction time.

      // Setup a language to have the defaults, but with overridden name.
      $default = new Language(array(
        'name' => $this->t("Site's default language (@lang_name)", array('@lang_name' => $default->getName())))
      );

When I try to fix other issues .. from the test logs ....I see this one fix has changed the execution path through the code and many of the other errors are changed. So I want to see what testbot says now...

Status: Needs review » Needs work

The last submitted patch, 23: name-2341341.23.patch, failed testing.

martin107’s picture

Assigned: martin107 » Unassigned

Further debugging, will happen slowly, first I need to fix this issue

#2355175: PHP Notice: Constant MENU_CALLBACK already defined when enumerating test classes

which is getting in the way.. but I will come back to this.

martin107’s picture

Assigned: Unassigned » martin107
Status: Needs work » Needs review
FileSize
825 bytes
39.95 KB

Now I understand the issue filed in #25 my subconscious can ignore it when I see it..

a) Found bug identical to #23 ... and where changing the name requires the construction of a new language object ( see update.inc )

b) The next fix to LanguageConfiguration.php makes DRUPAL\CONTENT_TRANSLATION\TESTS\CONTENTTRANSLATIONSYNCIMAGETEST pass.
It was just a stray example of $language->name not converted.. to $language->getName(). I found it by web testing with backtrace 'on'

martin107’s picture

FileSize
1.58 KB

Sorry bad interdiff

YesCT’s picture

Thanks. now the comment makes more sense. :)

+++ b/core/includes/update.inc
@@ -746,7 +746,9 @@ function update_language_list($flags = LanguageInterface::STATE_CONFIGURABLE) {
   if ($flags & LanguageInterface::STATE_SITE_DEFAULT) {
     $default = isset($default) ? $default : \Drupal::languageManager()->getDefaultLanguage();
     // Rename the default language.
-    $default->name = t("Site's default language (@lang_name)", array('@lang_name' => $default->getName()));
+    $default = new Language( array(
+     'name' =>  t("Site's default language (@lang_name)", array('@lang_name' => $default->getName()))
+    ));

maybe we dont need the $default right above that change either.
[edit]
this might not be so trivial as to just set the name on the new language... maybe we need to set other things it would have gotten from the getDefaultLanguage() like id (and maybe weight or direction).

this might be worth it's own little issue to fix this one test. I think we did a bunch of children out of the "Changes" issue to separate out tests that needed to be corrected before, so it wouldn't be too unusual to do that for this issue also.

Status: Needs review » Needs work

The last submitted patch, 26: name-2341341.26.patch, failed testing.

martin107’s picture

Status: Needs work » Needs review
FileSize
43.94 KB
4.4 KB

@YesCT - I think that needs a little refactoring also.

I think certainly a name change as inside the 'if'

 if ($flags & LanguageInterface::STATE_SITE_DEFAULT) {
   ..
    $default = isset($default) ? $default : \Drupal::languageManager()->getDefaultLanguage();
   ... 

the first assignment to $default, its only purpose is to extract what I want to call $defaultName. Fixing that up In another issue ..seems best.

BUT for now I am

A) just shamelessly cherry picking some obvious bugs, which showed up now that the tests are progressing a little further..

B) While cherry picking, I noticed that $language->name is a good thing to grep for.... so I found a few more.

martin107’s picture

Assigned: martin107 » Unassigned

Yay green!

vijaycs85’s picture

+++ b/core/includes/update.inc
@@ -746,7 +746,9 @@ function update_language_list($flags = LanguageInterface::STATE_CONFIGURABLE) {
     $default = isset($default) ? $default : \Drupal::languageManager()->getDefaultLanguage();
     // Rename the default language.
-    $default->name = t("Site's default language (@lang_name)", array('@lang_name' => $default->name));
+    $default = new Language( array(
+     'name' =>  t("Site's default language (@lang_name)", array('@lang_name' => $default->getName()))
+    ));

This looks wrong. We are getting default language and simply overriding with name? don't we have setName()?

alexpott’s picture

Status: Needs review » Needs work

I agree with @vijaycs85 that code block looks wrong - the default language is not necessarily the default values from new Language() - I think we need a setter for this use case of altering the default language label.

martin107’s picture

Status: Needs work » Needs review
FileSize
43.52 KB

This is a straight reroll caused by #2340667: Protect Drupal\Core\Language\Language::id, and use getId() landing :)

I will add the setter next...

Status: Needs review » Needs work

The last submitted patch, 34: name-2341341.34.patch, failed testing.

vijaycs85’s picture

+++ b/core/tests/Drupal/Tests/Core/PathProcessor/PathProcessorTest.php
@@ -9,6 +9,7 @@
 use Drupal\Core\Language\Language;
...
+use Drupal\Core\Language\Language;

yeah, auto-merge doesn't know namespace :) added twice.

martin107’s picture

Status: Needs work » Needs review
FileSize
42.93 KB
606 bytes
42.93 KB
606 bytes

@vijaycs85 thanks. and opps :)

The last submitted patch, 37: name-2341341.37.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 37: name-2341341.37.patch, failed testing.

YesCT’s picture

what happened to the change to PathProcessorTest from #30 ?

(small nit, let's stick with array() syntax. #2135291: [Policy, no patch] PHP 5.4 short array syntax coding standards for Drupal 8 is not decided yet.)

YesCT’s picture

Status: Needs work » Needs review

only 2 fails and they were ..

[13-Oct-2014 11:39:28 UTC] Uncaught PHP Exception InvalidArgumentException: "The URI "base://>j*>&:}A" is invalid. You must use a valid URI scheme. Use base:// for a path, e.g., to a Drupal file that needs the base path. Do not use this for internal paths controlled by Drupal." at /var/lib/drupaltestbot/sites/default/files/checkout/core/lib/Drupal/Core/Url.php line 207	Fatal error	Unknown	0	Unknown	
[13-Oct-2014 11:39:28 UTC] Uncaught PHP Exception InvalidArgumentException: "The URI "base://>j*>&:}A" is invalid. You must use a valid URI scheme. Use base:// for a path, e.g., to a Drupal file that needs the base path. Do not use this for internal paths controlled by Drupal." at /var/lib/drupaltestbot/sites/default/files/checkout/core/lib/Drupal/Core/Url.php line 207

is a random fail
#2353347: Random failure in DisplayPathTest
retesting.

YesCT queued 37: name-2341341.37.patch for re-testing.

YesCT’s picture

Status: Needs review » Needs work

ok. that is green, but I think we want the setter and to use it in update.inc

YesCT’s picture

Title: Change public 'name' property access on languages to getName() » Change public 'name' property access on languages to getName() and add back setName()
Status: Needs work » Needs review
FileSize
3.17 KB
45.06 KB

adds the setName... to both Language and ConfigurableLanguage
thought about making a separate issue, but I think it might be ok as part of making name protected, so it's here.

not sure about the unit test, if it is the correct way to test a setter.

also I didn't add a unit test to ConfigurableLanguageUnitTest. We might need to do that. Not sure.

[edit]
I also wonder if we should put a comment on setName, and try and explain that most of the time, a language should be created with it's name passed in the constructor, and warn about when we *should* use setName()

YesCT’s picture

+++ b/core/tests/Drupal/Tests/Core/Language/LanguageUnitTest.php
@@ -19,12 +19,15 @@ class LanguageUnitTest extends UnitTestCase {
+    $new_name = $this->randomMachineName();
+    $this->assertSame($language, $language->setName($new_name));

this doesn't seem correct to me. Cause if the setName didn't do anything at all, it could still pass.

YesCT’s picture

FileSize
677 bytes
45.07 KB

well, here is a different assert.
I'll wait for feedback.

vijaycs85’s picture

Just one more update for setName(). Everything else looks good.

Status: Needs review » Needs work

The last submitted patch, 47: 2341341-language-name-47.patch, failed testing.

vijaycs85’s picture

YesCT’s picture

FileSize
45.25 KB
910 bytes

ah, good.

I'm not sure about removing that clone... but ok. (there is a comment about why in #23 where it was taken out)

In this change, I'm just making the change in update.inc more like that one in LanguageManager

I think this needs a final review and might be rtbc now. oh, wait, it needs feedback (thinking) on the unit tests on setName().

penyaskito’s picture

Status: Needs review » Needs work

Some nitpicks...

  1. +++ b/core/includes/update.inc
    +++ b/core/includes/update.inc
    @@ -744,9 +744,10 @@ function update_language_list($flags = LanguageInterface::STATE_CONFIGURABLE) {
    

    We are missing the LanguageInterface import. Probably not in scope, however.

  2. +++ b/core/includes/update.inc
    @@ -744,9 +744,10 @@ function update_language_list($flags = LanguageInterface::STATE_CONFIGURABLE) {
    -    $default->name = t("Site's default language (@lang_name)", array('@lang_name' => $default->name));
    +    $name = t("Site's default language (@lang_name)", array('@lang_name' => $default->getName()));
    +    $default->setName($name);
    

    We don't need the variable, its value is not reused.

  3. +++ b/core/lib/Drupal/Core/Language/LanguageManager.php
    @@ -146,11 +146,10 @@ public function getLanguages($flags = LanguageInterface::STATE_CONFIGURABLE) {
    +      $name = $this->t("Site's default language (@lang_name)", array('@lang_name' => $default->getName()));
    +      $default->setName($name);
    

    Same here, we don't need $name.

YesCT’s picture

51.1 yeah #2226533-305: Changes to the Language class due to the LanguageInterface (followup) has some clean up that will fix that. So not doing it here.

I'll take out the $name temp var now.

YesCT’s picture

Status: Needs work » Needs review
FileSize
45.21 KB
1.6 KB
penyaskito’s picture

Status: Needs review » Reviewed & tested by the community

RTBC then.

catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed/pushed to 8.0.x, thanks!

  • catch committed 848dbc5 on 8.0.x
    Issue #2341341 by YesCT, martin107, vijaycs85, fran seva: Change public...
Gábor Hojtsy’s picture

Issue tags: -sprint

Thanks!

YesCT’s picture

wow! super thanks to everyone. :)

Status: Fixed » Closed (fixed)

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