Problem/Motivation

field level language are not correct handled

Proposed resolution

See patch

Remaining tasks

Wait for core : #1439692: Rename field language properties to langcode to land?

Original report by cutesquirrel

I have fields of type "taxonomy_term_reference" and field collections containing "taxonomy_term_reference".
With the joined patch, generated nodes contains selected terms in "taxonomy_term_reference" fields.
I'm not sure it's enough : I'm using taxonomy vocabularies with 'localize' translation mode.

Files: 
CommentFileSizeAuthor
#10 respect-field-translatability-1292294-10.patch636 bytesclemens.tolboom
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch respect-field-translatability-1292294-10.patch. Unable to apply patch. See the log in the details link for more information.
[ View ]
#6 respect-field-translatability-1292294-6.patch880 bytesPisco
PASSED: [[SimpleTest]]: [MySQL] 2 pass(es).
[ View ]
#4 respect-field-translatability-1292294-4.patch873 bytesPisco
PASSED: [[SimpleTest]]: [MySQL] 2 pass(es).
[ View ]
#2 respect-field-translatability-1292294-2.patch914 bytesPisco
PASSED: [[SimpleTest]]: [MySQL] 2 pass(es).
[ View ]
devel_generate.fields.inc_.20110927.patch922 bytescutesquirrel
PASSED: [[SimpleTest]]: [MySQL] 2 pass(es).
[ View ]

Comments

Status:Patch (to be ported)» Needs work

Patches must go against the current -dev version.

Please respect the Drupal coding conventions:

+++ b/devel_generate/devel_generate.fields.inc
@@ -60,12 +60,16 @@ function devel_generate_fields(&$object, $obj_type, $bundle) {
+    ¶

No trailing spaces.

+++ b/devel_generate/devel_generate.fields.inc
@@ -60,12 +60,16 @@ function devel_generate_fields(&$object, $obj_type, $bundle) {
+    // set language = undefined for some field types

Comments start with a capital letter and end with a dot.

+++ b/devel_generate/devel_generate.fields.inc
@@ -60,12 +60,16 @@ function devel_generate_fields(&$object, $obj_type, $bundle) {
+    $langcode = ( $field['type'] == 'taxonomy_term_reference' or $field['type'] == 'field_collection') ? LANGUAGE_NONE : $object->language;

No leading space inside parenthesis.

Use '||' rather than 'or'.

Finally, mark you issue "needs review."

Title:fields "taxonomy_term_reference" on translatable nodes not filled if you choice a language other than "undefined"Respect field translatability when generating content, otherwise it gets lost
Version:7.x-1.2» 7.x-1.x-dev
Status:Needs work» Needs review
StatusFileSize
new914 bytes
PASSED: [[SimpleTest]]: [MySQL] 2 pass(es).
[ View ]

This is indeed a bug. As of D7 there are fields that can be translated and others that can not be translated. devel_generate does not respect this at the moment. As a consequence, when generating content that has a language, in a content type that has fields which can not be translated, the generated values get lost during node_save. Each field instance has meta data telling wether it can or can not be translated, this simple patches fixes that issue while respecting the translatability of a field.

@cutesquirrel, your approach is wrong because it doesn't solve the problem in a generic way. taxonomy_term_reference is in no way special, thus in devel_generate there should not be special code for it. Have a look at my patch for a generic approach.

Version:7.x-1.x-dev» 8.x-1.x-dev
Status:Needs review» Patch (to be ported)

Committed to 7.x but failed to apply to 8.x. Could anyone reroll for 8?

Status:Patch (to be ported)» Needs review
StatusFileSize
new873 bytes
PASSED: [[SimpleTest]]: [MySQL] 2 pass(es).
[ View ]

Thanks for committing! This patch should work for the 8.x branch.

+++ b/devel_generate/devel_generate.fields.inc
@@ -61,7 +61,7 @@ function devel_generate_fields(&$object, $obj_type, $bundle) {
-    $object->{$field_name}{$object->language} = $object_field;
+    $object->{$field_name}{$field['translatable'] ?  $object->language : LANGUAGE_NONE} = $object_field;

Is this correct PHP? What's the meaning of
$object->{'foo'}{'bar'}
? Shouldn't this have been
$object->{'foo'}['bar']
? Or in our case
    $object->{$field_name}[$object->language]
and thus become
    $object->{$field_name}[$field['translatable'] ? $object->language : LANGUAGE_NONE] = $object_field;
?

(double space in ternary operator)

StatusFileSize
new880 bytes
PASSED: [[SimpleTest]]: [MySQL] 2 pass(es).
[ View ]

Thanks for the review @salvis, here's another try.

Looks good now, still needs review and testing...

Status:Needs review» Needs work

+++ b/devel_generate/devel_generate.fields.inc
@@ -61,7 +61,7 @@ function devel_generate_fields(&$object, $obj_type, $bundle) {
+    $object->{$field_name}[$field['translatable'] ? $object->language : LANGUAGE_NONE] = $object_field;

Please split this into two lines. That's way more readable :)

<?php
$language
= $field['translatable'] ? $object->language : LANGUAGE_NONE;
$object->{$field_name}[$language] = $object_field;
?>

Issue summary:View changes

Updated issue summary.

StatusFileSize
new636 bytes
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch respect-field-translatability-1292294-10.patch. Unable to apply patch. See the log in the details link for more information.
[ View ]

I added one comment and split into two lines of code.

This break as soon as core : #1439692: Rename field language properties to langcode lands.

Status:Needs work» Needs review

@clemens.tolboom: Thanks for working on the patch and for the heads up about langcode. Let's keep this separate, because the patch resulting from this issue here should still apply to D7, too.

@All: please review and test...

Status:Needs review» Needs work

I wish someone would have tested this...

The automated test says very little unfortunately, except that the patch still applies.

#10 is still intended to be applied to the D7 version, and we need an update for D8.

Status:Needs work» Needs review

@salvis #10 is for D8 :)

The patch applies probably as there are no tests written hitting this patch. But it will break locally now I guess.

So this needs review.

I think we have a more comprehensive patch here: #1549662: Node, taxonomy, comment, and user are all classed objects — I'd like to get that one committed and then see what's left.

Status:Needs review» Needs work

The last submitted patch, respect-field-translatability-1292294-10.patch, failed testing.

Issue summary:View changes

Updated issue summary.