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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

salvis’s picture

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."

Pisco’s picture

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
FileSize
914 bytes

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.

moshe weitzman’s picture

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?

Pisco’s picture

Status: Patch (to be ported) » Needs review
FileSize
873 bytes

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

salvis’s picture

+++ 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)

Pisco’s picture

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

blackandcode’s picture

salvis’s picture

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

clemens.tolboom’s picture

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 :)

$language = $field['translatable'] ? $object->language : LANGUAGE_NONE;
$object->{$field_name}[$language] = $object_field;
clemens.tolboom’s picture

Issue summary: View changes

Updated issue summary.

clemens.tolboom’s picture

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.

clemens.tolboom’s picture

Status: Needs work » Needs review
salvis’s picture

@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...

salvis’s picture

salvis’s picture

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.

clemens.tolboom’s picture

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.

salvis’s picture

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.

salvis’s picture

salvis’s picture

Status: Needs review » Needs work

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

Anonymous’s picture

Issue summary: View changes

Updated issue summary.

moshe weitzman’s picture

Issue summary: View changes
Status: Needs work » Closed (cannot reproduce)

This is very old. Please open a new issue if this is still a problem.