Follow-up to #1966436-250: Default *content* entity languages are not set for entities created with the API

Problem/Motivation

Issue was closed but there's @todo reference in code

/**
* Implements hook_install().
*/
function user_install() {
  $storage = \Drupal::entityManager()->getStorage('user');
  // @todo Rely on the default value for langcode in
  //   https://drupal.org/node/1966436
  $langcode = \Drupal::languageManager()->getDefaultLanguage()->getId();

Proposed resolution

Remove @todo and fix language assign in install for user

Remaining tasks

Fix

User interface changes

No

API changes

No

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Gábor Hojtsy’s picture

Status: Active » Needs review
FileSize
871 bytes

I don't think the default language will be applied so far as we use the storage directly instead of the entity API? Let's see what happens :D

andypost’s picture

Status: Needs review » Reviewed & tested by the community

It works!

andypost’s picture

Issue tags: +Needs tests

Do we need test for that?
Manually tested install with ru language - it works

alexpott’s picture

Status: Reviewed & tested by the community » Needs work

Yep we could add an assertion to InstallerTranslationTest

alexpott’s picture

So there is a KernelTestBase test for this - see UserInstallTest. But I don't trust it to properly test the integration of the installer, entity system and language so early during an install. So lets add an assertion to InstallerTranslationTest for this too.

Gábor Hojtsy’s picture

Based on git blame, #2148071: Cannot install in foreign language (Undefined index: und in ContentEntityBase->language()) added the langcode to user_install(). It did add a test to ensure the warning seen before did not appear anymore but no specific test as to what langcode the user was created in. We can add asserts to existing tests to ensure the user got created with a good langcode. InstallerTranslationTest looks good for this.

Gábor Hojtsy’s picture

Status: Needs work » Needs review
FileSize
1.98 KB
1.13 KB

Note also that UserInstallTest tests this with English and ensures both users get created with the site default language (English in that test). Here is a little update to InstallerTranslationTest to test that those get created in German.

Gábor Hojtsy’s picture

Issue tags: -Needs tests

Looks good? :)

andypost’s picture

Status: Needs review » Reviewed & tested by the community

exactly!

Gábor Hojtsy’s picture

Issue tags: +sprint
catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed/pushed to 8.0.x, thanks!

  • catch committed bee3e48 on 8.0.x
    Issue #2368081 by Gábor Hojtsy | andypost: Fixed Remove outdated @todo...
Gábor Hojtsy’s picture

Issue tags: -sprint

Superb, thanks!

Status: Fixed » Closed (fixed)

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