As per #1216094: We call too many things 'language', clean that up we are converting schemas and parallel APIs to use 'langcode' instead of 'language' where a language code is involved. The use of 'language' inconsistently for language objects and language codes in Drupal 7 keeps throwing people off the cliff and makes understanding the API much harder.

This issue is about user.module needing the same conversion to move from $user->language to $user->langcode. Will need updates and upgrade tests but first of all it would be a well focused search and replace wherever user language is involved.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

clemens.tolboom’s picture

Just some greps to get an idea

find . -exec grep -nH "\->language" {} \; | grep account
find . -exec grep -nH "\->language" {} \; | grep user
balagan’s picture

Assigned: Unassigned » balagan
balagan’s picture

Status: Active » Needs review
FileSize
2.41 KB

I have changed the $user->language to $user->langcode and $account->language to $account->langcode.
Also changed the language in database schema to langcode (user.install).

Status: Needs review » Needs work

The last submitted patch, 1439680.diff, failed testing.

balagan’s picture

FileSize
7.25 KB

Second try...

Gábor Hojtsy’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 1439680-2.patch, failed testing.

kalman.hosszu’s picture

Status: Needs work » Needs review
FileSize
11.15 KB

Patch attached.

fubhy’s picture

Status: Needs review » Needs work
+++ b/core/modules/simpletest/tests/upgrade/drupal-7.language.database.phpundefined
@@ -524,3 +524,40 @@ db_update('system')->fields(array(
+db_insert('users')->fields(array(
+  'uid',
+  'name',
+  'pass',
+  'mail',
+  'theme',
+  'signature',
+  'signature_format',
+  'created',
+  'access',
+  'login',
+  'status',
+  'timezone',
+  'language',
+  'picture',
+  'init',
+  'data',
+))
+->values(array(
+  'uid' => '12',
+  'name' => 'testuser',
+  'pass' => 'testpass',
+  'mail' => 'test@mydomain.com',
+  'signature' => '',
+  'signature_format' => '',
+  'created' => REQUEST_TIME,
+  'access' => 0,
+  'login' => 0,
+  'status' => 1,
+  'timezone' => '',
+  'language' => 'und',
+  'picture' => '',
+  'init' => 'test@mydomain.com',
+  'data' => '',
+))
+->execute();

This is not required. We can just use

db_insert('users')->fields(array(
  'uid' => '12',
  'name' => 'testuser',
  'pass' => 'testpass',
  'mail' => 'test@mydomain.com',
  'signature' => '',
  'signature_format' => '',
  'created' => REQUEST_TIME,
  'access' => 0,
  'login' => 0,
  'status' => 1,
  'timezone' => '',
  'language' => 'und',
  'picture' => '',
  'init' => 'test@mydomain.com',
  'data' => '',
))
->execute();
+++ b/core/modules/user/user.installundefined
@@ -351,6 +351,16 @@ function user_update_8000() {
+  );
+  db_change_field('users', 'language', 'langcode', $langcode_spec);
+  db_add_index('users', 'users_uid_langcode', array('uid', 'langcode'));

Is this a completely new index? If yes, what does it have to do with the patch? If not, where do we remove the old index? :)

kalman.hosszu’s picture

Status: Needs work » Needs review
FileSize
10.25 KB

Changed upgrade test method, and new index is removed.

fubhy’s picture

Status: Needs review » Reviewed & tested by the community

Ok, looks good now!

Gábor Hojtsy’s picture

Status: Reviewed & tested by the community » Needs review

Let's at least wait for the tests to come back green :)

Status: Needs review » Needs work

The last submitted patch, 1439680-10.patch, failed testing.

balagan’s picture

Status: Needs work » Needs review
FileSize
9.49 KB

3rd try... (needs merging with Kalman's upgrade patch)

kalman.hosszu’s picture

FileSize
3.49 KB

Merged with balagan's patch in comment 14.

fubhy’s picture

Status: Needs review » Needs work
+++ b/core/modules/user/user.installundefined
@@ -351,8 +351,16 @@ function user_update_8000() {
   }
+  ¶
+  $langcode_spec = array(

There is some unwanted whitespace in the line above $langcode_spec

balagan’s picture

Assigned: balagan » Unassigned
Gábor Hojtsy’s picture

@kalman.hosszu: your patch is much smaller then balagan's so its likely not merged. Can you post a merged version?

kalman.hosszu’s picture

Assigned: Unassigned » kalman.hosszu
Status: Needs work » Needs review
FileSize
12.49 KB

Sorry Gábor, I attached the unmerged file.

Attached again

Status: Needs review » Needs work

The last submitted patch, 1439680-19.patch, failed testing.

Gábor Hojtsy’s picture

The remaining test fails need to be fixed. Just two notes on the patch:

+++ b/core/modules/simpletest/tests/upgrade/upgrade.language.testundefined
@@ -47,4 +47,16 @@ class LanguageUpgradePathTestCase extends UpgradePathTestCase {
+    db_update('users')->fields(array('language' => 'und'))->condition('uid', '1')->execute();
+    $this->assertTrue($this->performUpgrade(), t('The upgrade was completed successfully.'));
+
+    // Directly check the user language property.
+    $user = db_query('SELECT * FROM {users} WHERE uid = :uid', array(':uid' => 1))->fetchObject();
+    $this->assertTrue($user->langcode == 'und', t('User language code found.'));

Can we set this to Catalan (available in the dump) instead just to be more interesting :)

+++ b/core/modules/user/user.installundefined
@@ -351,6 +351,15 @@ function user_update_8000() {
+
+  $langcode_spec = array(
+    'type' => 'varchar',
+    'length' => 12,
+    'not null' => TRUE,
+    'default' => '',
+    'description' => "Language code, e.g. 'de' or 'en-US'.",
+  );
+  db_change_field('users', 'language', 'langcode', $langcode_spec);
 }

This should go to a new update function and not extend an existing one (to support D8-D8 upgrade path).

kalman.hosszu’s picture

Status: Needs work » Needs review
FileSize
12.5 KB

I changed the patch based on Gábor's comments.

The remaining failed tests need to be fixed.

Status: Needs review » Needs work

The last submitted patch, 1439680-22.patch, failed testing.

kalman.hosszu’s picture

Status: Needs work » Needs review
FileSize
14.73 KB

Some of the failed tests are fixed. The openID test fix is remained.

Status: Needs review » Needs work

The last submitted patch, 1439680-24.patch, failed testing.

effulgentsia’s picture

In #1444992-12: Add langcode property in file schema, Damien says:

{node}.language and {users}.language are two *completely* different animals. The language attached to the user is the *default language of the user*, not the language of the user entity.

It seems like between this issue, that one, #1444966: Add langcode property in taxonomy schema, and perhaps others, we're trying to have a consistent langcode property for all entity types, but that for users, the meaning of this property is different. Should we actually be renaming this property to something like preferred_langcode and adding a separate langcode column for identifying the language of the entity itself?

tstoeckler’s picture

tstoeckler’s picture

Oops, hadn't seen that was closed. Hmm....

effulgentsia’s picture

Hah! I hadn't seen that issue, or that Gabor proposed the same name :)

kalman.hosszu’s picture

Status: Needs work » Needs review
FileSize
15.46 KB

The new patch is attached.

Gábor Hojtsy’s picture

@effulgentsia: yes, I clearly thought originally that we should treat $user separately at first. *But* (a) nobody else cared for a month, which was a clear sign this should not be complicated, see that issue (b) even if we want to separate the two meanings, we do want to have a langcode in any case (meaning the language code for the user entity). So if we branch the $user->language to two properties, one would be 'langcode', and in updates, the best we can ensure is that that langcode is what 'language' was before, so we need to update the existing language and use that data in langcode either way.

Then if there is a true interest in branching this property out to two things, then we can do that as a next step too. I don't think we'd want to expose two language selectors on the user UI for example (select your profile data language here and then select your preferred site language here in the next dropdown), so the default built-in UI/behavior would be to handle both as the same and sync their values anyway, right? That is likely why nobody cared for the existing issue where I'd have started with a different name at first.

If we do want to change to preferred_langcode first, we can certainly do that here, but we'll need a 'langcode' type value anyway to support the user entity/field language backend (and that would be derived from the same language property in upgrades from D7).

What do you think?

Gábor Hojtsy’s picture

BTW we can also spawn to langcode *and* preferred_langcode here right away and choose either to expose on the UI and just make the other a #type => value so a contrib / site specific module can make it exposed if they want to make the two things separate, otherwise just use the same value for both when saved/changed?

effulgentsia’s picture

Issue tags: -D8MI, -sprint, -langcode, -language-content

#30: 1439680-30.patch queued for re-testing.

Status: Needs review » Needs work
Issue tags: +D8MI, +sprint, +langcode, +language-content

The last submitted patch, 1439680-30.patch, failed testing.

effulgentsia’s picture

Status: Needs work » Needs review
FileSize
15.49 KB

This is just a reroll of #30 for chasing HEAD.

effulgentsia’s picture

FileSize
17.63 KB

Re #32: yeah, I think we should deal with both langcode and preferred_langcode in this one issue.

Here's a patch that renames the existing language field to preferred_langcode, and adds a *new* langcode field that defaults to LANGUAGE_NONE, just as in #1444992: Add langcode property in file schema and #1444966: Add langcode property in taxonomy schema. I see no reason why core should assume that langcode has any relationship to preferred_langcode. Instead, when we figure out what logic core and contrib should use for determining the langcode of taxonomy terms and files, then I imagine a similar logic/workflow will be needed for account profiles, independently of users configuring their preferred site language. But, this is just my naive gut feeling. If you have experience to suggest there is a relationship between the two that we should maintain, please educate me.

Gábor Hojtsy’s picture

Status: Needs review » Needs work

@effulgentsia: I do think making it possible to have separate preferred language and entity language for users as a possibility is good. I dont think we should expose that in core though, having two language fields on your user profile is puzzling at best. Also, since there is no separation for the two values in D7, the language is also used as entity language in contrib modules so I think the only logical way to handle this is to (a) upgrade to have both new properties use the same value (b) maintain both values as equal until we have any good idea as to how to expose them separately (or contrib will do that).

effulgentsia’s picture

Status: Needs work » Closed (duplicate)
Gábor Hojtsy’s picture

Issue tags: -sprint

Removing outdated tags.