Active
Project:
Field collection
Version:
7.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
31 May 2016 at 13:42 UTC
Updated:
31 May 2016 at 13:56 UTC
Jump to comment: Most recent
An entity metadata wrapper on a field collection item doesn't work correctly when used with entity translation. As an example see this test code that was recently replaced:
$fc_entity = entity_create('field_collection_item', $values);
$fc_entity->setHostEntity('node', $node, $translation_langcode);
- $fc_wrapper = entity_metadata_wrapper('field_collection_item', $fc_entity);
- $fc_wrapper->{$this->field_untrans_name}->set(self::UNTRANS_FIELD_DE_MOD);
- $fc_wrapper->{$this->field_trans_name}->set(self::TRANS_FIELD_DE_MOD);
- $fc_wrapper->save(TRUE);
+ $fc_entity->{$this->field_untrans_name}[LANGUAGE_NONE][0]['value'] = self::UNTRANS_FIELD_DE_MOD;
+ $fc_entity->{$this->field_trans_name}['de'][0]['value'] = self::TRANS_FIELD_DE_MOD;
+ $fc_entity->save(TRUE);
The problem with the original version is that the value in field_trans_name would be saved in the default language 'en' instead of in $translation_langcode like it should be.
Comments
Comment #2
james.williamsIs this just because the following is needed to tell the EMW what language to operate in?
i.e. the language needs to be explicitly set, as EMW doesn't infer the appropriate one to use.
I may be missing something bigger, that's just my initial instinctual guess, based on plenty of experience of related EMW+language issues.