Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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
Comment | File | Size | Author |
---|---|---|---|
#7 | interdiff.txt | 1.13 KB | Gábor Hojtsy |
#7 | 2368081-user-install-langcode-7.patch | 1.98 KB | Gábor Hojtsy |
#1 | 2368081-user-install-langcode.patch | 871 bytes | Gábor Hojtsy |
Comments
Comment #1
Gábor HojtsyI 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
Comment #2
andypostIt works!
Comment #3
andypostDo we need test for that?
Manually tested install with ru language - it works
Comment #4
alexpottYep we could add an assertion to InstallerTranslationTest
Comment #5
alexpottSo 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.Comment #6
Gábor HojtsyBased 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.
Comment #7
Gábor HojtsyNote 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.
Comment #8
Gábor HojtsyLooks good? :)
Comment #9
andypostexactly!
Comment #10
Gábor HojtsyComment #11
catchCommitted/pushed to 8.0.x, thanks!
Comment #13
Gábor HojtsySuperb, thanks!