As part of the D8 multilingual initiative, we want to add a langcode property to all entity types, just like we currently already have for nodes and comments.

This issue is a merging of prior work done in #1444966: Add langcode property in taxonomy schema, #1439680: Rename $user language property to langcode, and #1444992: Add langcode property in file schema to make it easier for reviewers and committers to track this in one patch. Committers: please credit the sprint participants from the prior issues, hairqles, kalman.hosszu, balagan, csg in addition to this issue's participants when committing this.

Patch summary:

  • Adds a langcode field to {file_managed}. A hook_update_N() function sets existing files to LANGUAGE_NONE for reasons explained in the code comments. file_save() defaults $file->langcode to LANGUAGE_NONE. Tests included for the update hook and ability to file_save() with a desired langcode.
  • Adds a langcode field to {taxonomy_vocabulary} and {taxonomy_term_data}. A hook_update_N() function sets existing vocabularies and terms to language_default()->langcode. taxonomy_vocabulary_save() and taxonomy_term_save() do not apply any default langcode, just as nodes and comments do not in their save functions. Patch adds explicit langcode in tests and install code that calls the save functions directly. taxonomy_form_vocabulary() and taxonomy_form_term() set a default of language_default()->langcode, with an @todo pointing to #258785: Provide more flexible settings for initial language on content types. There is no language selector UI on these forms yet, as per the issue summary on #1444966: Add langcode property in taxonomy schema. Tests are included for the upgrade path, but not for anything else, as per #1444966-18: Add langcode property in taxonomy schema.
  • Splits {users}.language into 2 fields: langcode and preferred_langcode. Code added to locale module to make its one language selector control both properties, as per #1439680-37: Rename $user language property to langcode. Code comments added for instructing how a contrib module can override this synchronization. Tests included for the upgrade path and existing locale.test assertions expanded to cover both properties.

Comments

gábor hojtsy’s picture

Issue tags: +sprint
effulgentsia’s picture

Assigned: effulgentsia » Unassigned
Status: Active » Needs review
StatusFileSize
new35.32 KB

Gabor, I think this captures everything we discussed from the other issues and in chat. Can you review and confirm?

effulgentsia’s picture

StatusFileSize
new35.32 KB
+++ b/core/includes/file.inc
@@ -568,6 +568,9 @@ function file_load($fid) {
+  if (empty($file->langcode)) {
+    $file->langcode = LANGUAGE_NONE;
+  }

This should be !isset(). This patch fixes that.

effulgentsia’s picture

Issue summary: View changes

Updated issue summary.

effulgentsia’s picture

Issue summary: View changes

Updated issue summary.

effulgentsia’s picture

Issue summary: View changes

Updated issue summary.

Status: Needs review » Needs work

The last submitted patch, 1454538-3.patch, failed testing.

effulgentsia’s picture

Status: Needs review » Needs work
StatusFileSize
new34.86 KB

The #3 errors were due to me adding an incorrect 'langcode' => LANGUAGE_NONE where the Forum test submits a vocabulary edit form. As noted in the summary, this issue is not about adding a UI to the vocabulary and term forms: that will come in a follow-up, so this patch removes this erroneous change to forum.test.

effulgentsia’s picture

Status: Needs work » Needs review
gábor hojtsy’s picture

First of all, thanks for this fantastic patch! I spent considerable time with reviewing this patch today (and we discussed this in detail while you wrote it last Friday). All-in-all I think it looks very solid. The initialization for files and terms/vocabularies for upgraded sites looks good. The snippets to sync the user preferred/entity language by default look great. We can retain our simple UI while providing flexibility for those who want to separate preferred language from entity language. I only found very minor issues that I think @xjm would point out sooner or later :)

+++ b/core/modules/locale/locale.moduleundefined
@@ -236,17 +236,41 @@ function locale_language_selector_form($user) {
+ * #value_callback of user register and profile forms' langcode element.

+++ b/core/modules/system/system.installundefined
@@ -1666,6 +1673,40 @@ function system_update_8002() {
+ * Add the {file_managed}.langcode field.

+++ b/core/modules/taxonomy/taxonomy.installundefined
@@ -245,4 +259,44 @@ function taxonomy_field_schema($field) {
+ * Add a langcode field to {taxonomy_term_data} and {taxonomy_vocabulary}.

+++ b/core/modules/user/user.installundefined
@@ -354,5 +361,40 @@ function user_update_8000() {
+ * Split the {users}.language field to langcode and preferred_langcode.

Summaries should start with 3rd person verbs now.

PS. also asked @fubhy and @tstoeckler to review this patch, hope they can get to it soon.

Leaving needs review since the issues are very minor.

kalman.hosszu’s picture

Status: Needs work » Needs review
StatusFileSize
new34.85 KB

3rd person verbs are fixed.

xjm’s picture

gábor hojtsy’s picture

@xjm: In other words, its fine as it is now :)

fubhy’s picture

Status: Needs review » Needs work

Maybe this is just nitpicking, but those two issues are the very last things that I noticed. Feel free to ignore them as they probably are irrelevant.

+++ b/core/modules/locale/locale.moduleundefined
@@ -236,17 +236,41 @@ function locale_language_selector_form($user) {
+    // than the preferred_langcode element. Set a large weight here in case
+    // module's alter the weight of the other element.

This should just read "modules" (not module's). Maybe even rephrase it to "... in case a module alters the weight of the other element."

+++ b/core/modules/locale/locale.moduleundefined
@@ -236,17 +236,41 @@ function locale_language_selector_form($user) {
 /**
+ * Sets value of user register and profile forms' langcode element.

This is a private function so it doesn't really matter but maybe we could use proper grammar like "Sets the value of the user register and profile forms' langcode element."

Other than that it looks nice and ready to go.

gábor hojtsy’s picture

Status: Needs work » Needs review
StatusFileSize
new34.86 KB

Those two text change suggestions are great IMHO, so here they are. Any other concerns?

moshe weitzman’s picture

Status: Needs review » Reviewed & tested by the community

This looks good to me. I'm hoping that we can standardize some of this code soon into entity.module.

I think a lot of eyes have +1 this in addition to me so RTBC.

fastangel’s picture

I've tested and it works perfectly.

plach’s picture

Status: Reviewed & tested by the community » Needs work

This is indeed a great first step towards having language support enabled on any entity (the next logical step would be to factor out the language support logic/ui and move them to the base entity object/module). Just a couple of notes:

+++ b/core/includes/file.inc
@@ -568,6 +568,9 @@ function file_load($fid) {
+  if (!isset($file->langcode)) {
+    $file->langcode = LANGUAGE_NONE;
+  }

+++ b/core/modules/taxonomy/taxonomy.admin.inc
@@ -117,6 +117,8 @@ function taxonomy_form_vocabulary($form, &$form_state, $edit = array()) {
+      'langcode' => language_default()->langcode,

@@ -659,6 +661,8 @@ function taxonomy_form_term($form, &$form_state, $edit = array(), $vocabulary =
+      'langcode' => language_default()->langcode,

The related update functions nicely explain the reasons why they are defaulting to the (different) values above. Also these lines could use an explicit comment clarifying them.

+++ b/core/modules/system/system.install
@@ -1666,6 +1673,40 @@ function system_update_8002() {
+    // According to the documentation of db_change_field(), indeces using the
+    // field should be dropped first; if the contrib module created any indeces,
+    // it is its responsibility to drop them in an update function that runs
+    // before this one, which it can enforce via hook_update_dependencies().

+++ b/core/modules/taxonomy/taxonomy.install
@@ -245,4 +259,44 @@ function taxonomy_field_schema($field) {
+      // According to the documentation of db_change_field(), indeces using the
+      // field should be dropped first; if the contrib module created any
+      // indeces, it is its responsibility to drop them in an update function
+      // that runs before this one, which it can enforce via
+      // hook_update_dependencies().

This looks sensible to me, I'm just wondering what is supposed to happen in the case of the Entity translation module, which is the most likely candidate to mess with the entity 'langcode' columns in D7 (see #1280546: Introduce a language selection widget for every entity). Since it is going to be moved to core in D8, who will be responsible to perform this update properly? I'd say needing to install an 8.x version of the ET module just to be able to upgrade would be nonsensical.

26 days to next Drupal core point release.

gábor hojtsy’s picture

Status: Needs work » Reviewed & tested by the community

@plach: re your first note, this is being addressed with #258785: Provide more flexible settings for initial language on content types and the code in question added by this patch is likely not there for longer than a month or two. Let's not ping-pong this with that given we want to move setting of defaults to a versatile UI.

Your second note did not have any consequences for the status of this patch. I think that question comes up when/if ET introduces a language property on entities. We can *then* add the same update code like we have for users except with a condition for whether a language field existed if we want to solve that in core. We usually don't have migration path for contrib modules in core, so the other alternative is for ET to have a D7 release which people should update to before updating to D8. That release would prepare the entity tables to have langcode like D8 expects, in which case we already have code in this patch to cover that situation.

Let's have this land and work towards flexible defaults in #258785: Provide more flexible settings for initial language on content types.

gábor hojtsy’s picture

StatusFileSize
new35.38 KB
new2 KB

Here is the requested doc update anyway, since the patch needed a reroll due to another D8MI patch landing. It is just a doc change as per requested, should not change RTBC status.

Note once again that parts of this patch were worked on by MANY people and it was reviewed by *many* people earlier in previous issues at #1444966: Add langcode property in taxonomy schema, #1439680: Rename $user language property to langcode, #1444992: Add langcode property in file schema, so if this issue looks slim and unrealistic to work out a change of this scale, just add up the existing work from all of those issues.

dries’s picture

Status: Reviewed & tested by the community » Fixed

Committed to 8.x. Great start for adding better language support to entities.

webchick’s picture

There was a collision with update numbers, but I just went in and fixed it. http://drupalcode.org/project/drupal.git/blobdiff/2d6dcdd509126c6ab86e0c...

gábor hojtsy’s picture

Issue tags: -sprint

Fantastic! Thanks, removing sprint tag.

Now onto making language based data accessibility (fields/properties) much simpler at #1277776: Add generic field/property getters/setters (with optional language support) for entities.

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

Anonymous’s picture

Issue summary: View changes

Updated issue summary.