Spawning an issue from

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

it would be nice to hive off all the changes such as

- $langcode = $langcode ? $langcode : \Drupal::languageManager()->getCurrentLanguage(LanguageInterface::TYPE_CONTENT)->id;
+ $langcode = $langcode ? $langcode : \Drupal::languageManager()->getCurrentLanguage(LanguageInterface::TYPE_CONTENT)->getId();

into a separate issue... to make the review process a breeze

Well this is it..

Comments

martin107’s picture

Title: Use language->getId() » Protect Drupal\Core\Language\Language::id, and use getId()
Status: Needs work » Needs review
StatusFileSize
new255.75 KB

After about 70mins of work on this .. I have made so many changes that I need to see if I have made any gross mistakes before continuing.

Please don't consider this ready for review....just for testbot inspection.

My sense is that I have almost stripped out all but the wanted changes ( My starting point was 2226533.291.patch see parent)

When I said it would be a breeze to review... err well it is still going to be a >200Kb monster :)

Status: Needs review » Needs work

The last submitted patch, 1: getId-2340667-1.patch, failed testing.

martin107’s picture

Status: Needs work » Needs review
StatusFileSize
new254.45 KB

Patched up the most frequently recurring bugs

Still expect problems...

Status: Needs review » Needs work

The last submitted patch, 3: getId-2340667-3.patch, failed testing.

martin107’s picture

Status: Needs work » Postponed

This patch is so large it will need a daily reroll... ( It needs a reroll now )
It seems appropriate to postpone until the other issue spawned skrink the parent issue down a bit

alexpott’s picture

Status: Postponed » Needs review
StatusFileSize
new202.15 KB

I'm not sure I agree about postponing this issue - it certainly does not need to go in before the beta but it actually easy to reroll since the correct thing to do with be always to accept the changes from HEAD and redo the fixes - which is exactly what did not occur earlier so other changes got partially reverted in the patches.

Status: Needs review » Needs work

The last submitted patch, 6: 2340667.6.patch, failed testing.

yesct’s picture

I'm ok with rerolling this frequently.

I agree we should resolve the conflicts usually by keeping what is in head, and then doing what the patch is intending... usually changing ->id to ->getId() ... etc.

alexpott’s picture

Status: Needs work » Needs review
StatusFileSize
new1.53 KB
new201.45 KB

Fixed test fails.

martin107’s picture

I have taken a slow and steady visual scan of this patch ... in short everything looks appropriate, with a few exceptions.

I have found a few mis filtered ( by myself, I suspect ) changes that are technically out of scope ... but they are so small I don't propose we go to the effort of removing what are after all improvements..

the first one is also part of a sister patch to pick out annotation improvements.

  1. +++ b/core/lib/Drupal/Core/TypedData/TranslatableInterface.php
    @@ -27,7 +27,7 @@ public function language();
        *
    ...
    +   * @return \Drupal\Core\Language\LanguageInterface[]
    
  2. +++ b/core/modules/hal/src/Normalizer/FieldNormalizer.php
    @@ -26,9 +26,11 @@ class FieldNormalizer extends NormalizerBase {
    +    /** @var \Drupal\Core\Field\FieldItemInterface $field */
    ...
     
    ...
    +    /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
    
alexpott’s picture

StatusFileSize
new199.55 KB

Left #10.1 in since it related to this patch as we're using this method on the array elements returned by this patch. Removed #10.2 since yep it is unrelated change.

Rerolled.

martin107’s picture

Assigned: martin107 » Unassigned
Pedro Lozano’s picture

StatusFileSize
new189.6 KB

Reroll.

Status: Needs review » Needs work

The last submitted patch, 13: 2340667.patch, failed testing.

Pedro Lozano’s picture

Status: Needs work » Needs review
StatusFileSize
new29.82 KB

Trying to fix all those ->id references.

martin107’s picture

Hi Pedro, just looking at the change in patch size .... down 85% .. did another issue make most of the changes redundant?

alexpott’s picture

Status: Needs review » Needs work

Nope and the id properties are no longer protected... perhaps the patches should be combined.

Pedro Lozano’s picture

Status: Needs work » Needs review
StatusFileSize
new193.67 KB

Sorry for the screw up guys, it is my first patch work in a long time.

This should be the complete patch.

Status: Needs review » Needs work

The last submitted patch, 18: protect-2340667-18.patch, failed testing.

Pedro Lozano’s picture

Status: Needs work » Needs review
StatusFileSize
new197.1 KB

Fixing more instances of ->id.

Status: Needs review » Needs work

The last submitted patch, 20: protect-2340667-20.patch, failed testing.

Pedro Lozano’s picture

Status: Needs work » Needs review
StatusFileSize
new198.49 KB
dawehner’s picture

  1. +++ b/core/lib/Drupal/Core/Page/DefaultHtmlFragmentRenderer.php
    @@ -100,7 +100,7 @@ public function preparePage(HtmlPage $page, &$page_array) {
    -    $html_attributes['lang'] = $language_interface->id;
    +    $html_attributes['lang'] = $language_interface->getId();
    

    It is odd that we have ->id() on entities and ->getId()here, quite confusing actually.
    This bit should be directly at least described in the IS ...

  2. +++ b/core/modules/book/book.module
    @@ -478,7 +478,7 @@ function template_preprocess_book_export_html(&$variables) {
       $attributes['dir'] = $language_interface->direction ? 'rtl' : 'ltr';
    

    This will have a small conflict with #2070737: Change values of LanguageInterface::DIRECTION_(LTR/RTL) to ('ltr'/'rtl'). Just to keep in mind, maybe.

  3. +++ b/core/tests/Drupal/Tests/Core/Entity/EntityManagerTest.php
    @@ -114,11 +114,15 @@ protected function setUp() {
    +    $language = $this->getMock('Drupal\Core\Language\LanguageInterface');
    +    $language->expects($this->any())
    +      ->method('getId')
    +      ->will($this->returnValue('en'));
    ...
    -      ->will($this->returnValue((object) array('id' => 'en')));
    +      ->will($this->returnValue($language));
    

    Much better if you ask me. Just as a general tip (not a review) you can use ->willReturnValue($language)); This safes a little bit of typing which is really nice.

  4. +++ b/core/tests/Drupal/Tests/Core/PathProcessor/PathProcessorTest.php
    @@ -44,10 +45,8 @@ protected function setUp() {
    -    foreach (array('en' => 'English', 'fr' => 'French') as $langcode => $language_name) {
    -      $language = new \stdClass();
    -      $language->id = $langcode;
    -      $language->name = $language_name;
    +    foreach (array('en', 'fr') as $langcode) {
    +      $language = new Language(array('id' => $langcode));
           $languages[$langcode] = $language;
    

    What happened with the name? Should we just try to move this over?

Pedro Lozano’s picture

StatusFileSize
new198.49 KB

@dawehner Since I'm not the original author of the patch I can't comment much on the issues you pointed out.

IMHO

1. Yes, I'm also confused about it. And one implementation of getId() is return $this->id() and the other one is return $this->id.

2. I just rerolled and got no conflict on that part. But got a conflict about the change from ContentEntityInterface to FieldableEntityInterface, that I solved in favor of FieldableEntityInterface.

Uploading just a reroll.

martin107’s picture

I agree the ->id() or -> getId() is horribly inconsistent - Please not that I am not expressing an opinion one way or the other on which I prefer.

I want to speak neutrally, and just detail some facts in order to aid a more informed discussion, and prevent a bike shed moment.

I think we should fall in line with the entity way of doing things, for a greatest consistency.

I have included a link to just an entity discussion and and note it is an active issue. That debate is not new. - others may comment that we are we are in beta now and the way forward is settled.

dawehner’s picture

Issue tags: +D8MI

Yeah, so what should we do here. D8MI people?

yesct’s picture

Issue tags: +Amsterdam2014

renaming getId() to id() is a separate issue. and the opposite of .. #2246695: replace all core usages of id() with getid()

@tstoeckler suggested adding getId() to EntityBase and EntityInterface and marking id() deprecated. Anyway.. not the problem of this issue.

yesct’s picture

I rerolled the one from 11 to check the one from 24, which also needed a reroll.
The results were different. So I'm doing it again. (right now.)

patch coming in a bit.

yesct’s picture

one of the issues conflicting with this was #2341927: Language module annotation improvements [ plus minor followup ]
I'm not sure if we want it to be getId() ... guess can see if there are any fails.
$this->langcodes[$i] = $language->id();

anyway.

attached is the reroll of 11, and of 24.
and an interdiff of those.

for example,
- $this->assertTrue($this->entity->language()->getID() == 'en');
+ $this->assertTrue($this->entity->language()->getId() == 'en');

I think we should go with the reroll of 11. ... guess we should see what the testbot says.

Status: Needs review » Needs work

The last submitted patch, 29: 2340667.28.from11.patch, failed testing.

yesct’s picture

Status: Needs work » Needs review
StatusFileSize
new197.8 KB
new892 bytes

I missed one.
This should pass.

oh, of course it needs a reroll. ... for ... #2123867: Simplify/cleanup language handling in EntityFormController
looks like those hunks just went away.

yesct’s picture

Status: Needs review » Needs work

I will reroll this now.

yesct’s picture

Status: Needs work » Needs review
StatusFileSize
new196.8 KB

automatic 3-way merge. no conflicts.

yesct’s picture

StatusFileSize
new197.3 KB
new510 bytes

ok. *deep breath*

making id protected on ConfigurableLanguage also. Let's see how this does.

yesct’s picture

StatusFileSize
new197.29 KB
new1.64 KB

cool green again.

I read through all the lines of this patch.

Most are straight forward ->id to ->getId()

some are changes in the test that were setting id, and so have been reworked around doing that.

while reading I found one ->name to ->getName() that snuck in. I took that out.
And since starting all this a long time ago, I have noticed #2305593: [policy] Set a standard for @var inline variable type declarations so have fixed the change here to be better for more IDEs.

I think this is ready.

For a reviewer, try using the git --color-words in your diff to make reviewing easier.

yesct’s picture

Issue tags: +sprint

I think we could actually get this done. putting on the sprint board for d8mi.

yesct’s picture

Status: Needs review » Needs work

I am rerolling this now.

yesct’s picture

Status: Needs work » Needs review
StatusFileSize
new197.38 KB

Status: Needs review » Needs work

The last submitted patch, 38: 2340667.38.patch, failed testing.

yesct’s picture

Status: Needs work » Needs review
StatusFileSize
new197.39 KB

oops. I missed a conflict.
fixed.

  $node = $variables['node'];
  if ($node->language()->getId() != LanguageInterface::LANGCODE_NOT_SPECIFIED) {

$node did not know what kind of thing it is, so I told it with a @var.

vijaycs85’s picture

Issue tags: +Avoid commit conflicts
+++ b/core/tests/Drupal/Tests/Core/PathProcessor/PathProcessorTest.php
@@ -44,10 +45,8 @@ protected function setUp() {
-      $language->name = $language_name;

Looks like we missed the name while converting. Except that, +1 to RTBC.

The changes spread across all over the core. Would be great to get it in in before any other issues to avoid merge conflicts and reroll pains.

yesct’s picture

well, name is being done in #2341341: Change public 'name' property access on languages to getName() and add back setName()

ah, in this hunk in PathProcessorTest

     // Set up some languages to be used by the language-based path processor.
     $languages = array();
-    foreach (array('en' => 'English', 'fr' => 'French') as $langcode => $language_name) {
-      $language = new \stdClass();
-      $language->id = $langcode;
-      $language->name = $language_name;
+    foreach (array('en', 'fr') as $langcode) {
+      $language = new Language(array('id' => $langcode));
       $languages[$langcode] = $language;

Yeah, when we converted this test instead of making a new object and then setting the id and name, to: passing the needed info in the constructor.. that name was not needed at all. So that is why the line is taken out and a corresponding line not added back. [edit] So I think this is an ok change here.

vijaycs85’s picture

Status: Needs review » Reviewed & tested by the community

Alright. let's get this in.

martin107’s picture

Minor point regarding my comments from #25, given where we are today ... I am now convinced that this is the best way forward.
Just didn't want to hold up the review process.

alexpott’s picture

  1. +++ b/core/modules/user/src/Tests/UserInstallTest.php
    @@ -47,8 +47,8 @@ public function testUserInstall() {
    -    $this->assertEqual($anon->langcode, \Drupal::languageManager()->getDefaultLanguage()->id);
    -    $this->assertEqual($admin->langcode, \Drupal::languageManager()->getDefaultLanguage()->id);
    +    $this->assertEqual($anon->langcode, \Drupal::languageManager()->getDefaultLanguage()->getId(), 'Anon user language is the default.');
    +    $this->assertEqual($admin->langcode, \Drupal::languageManager()->getDefaultLanguage()->getId(), 'Admin user language is the default.');
    

    The test assertion message here is less useful to a developer than the default - which would tell you what the two langcodes are.

  2. +++ b/core/tests/Drupal/Tests/Core/Utility/TokenTest.php
    @@ -70,8 +70,10 @@ public function testGetInfo() {
    -    $language = $this->getMock('\Drupal\Core\Language\Language');
    -    $language->id = $this->randomMachineName();
    +    $values = array('id' => $this->randomMachineName());
    +    $language = $this->getMockBuilder('\Drupal\Core\Language\Language')
    +      ->setConstructorArgs(array($values))
    +      ->getMock();
    

    This is not a real mock :) Since we don't actually mock any functions might as well just create a language object. If we want to use mocks then we should mock the interface and the getId() method. However this is out-of-scope for this change and should be dealt with in a new issue.

Neither of the two above issues should hold up this change - let's get this done.

catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed/pushed to 8.0.x, thanks!

  • catch committed 66762a5 on 8.0.x
    Issue #2340667 by YesCT, Pedro Lozano, alexpott, martin107: Protect...
yesct’s picture

gábor hojtsy’s picture

Issue tags: -sprint +language-base

Thanks!

Status: Fixed » Closed (fixed)

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