Commit 89dcbb25 authored by Ra Mänd's avatar Ra Mänd
Browse files

Fix nested positive ifs.

parent 7ca870e7
......@@ -526,14 +526,13 @@ class FieldCollectionItemEntity extends Entity {
foreach ($fields_instances as $translatable_field) {
if ($fields[$translatable_field]['translatable'] == 1) {
foreach ($target_languages as $langcode) {
if (isset($this->{$translatable_field}[$source_language])) {
// Source (translatable_field) is set, therefore continue
// processing.
if (!isset($this->{$translatable_field}[$langcode])) {
// Destination (translatable_field) is not set, therefore safe to
// copy the translation.
$this->{$translatable_field}[$langcode] = $this->{$translatable_field}[$source_language];
}
// Source (translatable_field) is set, therefore continue
// processing.
if (isset($this->{$translatable_field}[$source_language])
&& !isset($this->{$translatable_field}[$langcode])) {
// Destination (translatable_field) is not set, therefore safe to
// copy the translation.
$this->{$translatable_field}[$langcode] = $this->{$translatable_field}[$source_language];
}
}
if ($source_language == LANGUAGE_NONE && count($this->{$translatable_field}) > 1) {
......
......@@ -707,10 +707,9 @@ function field_collection_field_load($entity_type, $entities, $field, $instances
*/
function field_collection_field_delete_revision($entity_type, $entity, $field, $instance, $langcode, &$items) {
foreach ($items as $item) {
if (!empty($item['revision_id'])) {
if ($entity = field_collection_item_revision_load($item['revision_id'])) {
$entity->deleteRevision(TRUE);
}
if (!empty($item['revision_id'])
&& $entity = field_collection_item_revision_load($item['revision_id'])) {
$entity->deleteRevision(TRUE);
}
}
}
......@@ -2070,20 +2069,18 @@ function field_collection_entity_translation_insert($entity_type, $entity, $tran
if (!empty($value[$language])) {
$source_items = !empty($entity->{$field_name}[$source_language]) ? field_collection_field_item_to_ids($entity->{$field_name}[$source_language]) : array();
foreach ($value[$language] as $delta => $field_value) {
if (!isset($field_value['entity'])) {
if ($fc_entity = field_collection_field_get_entity($field_value)) {
// Check if this field collection item belongs to the source language
if (in_array($fc_entity->item_id, $source_items)) {
// Clone the field collection item
$new_fc_entity = clone $fc_entity;
$new_fc_entity->item_id = NULL;
$new_fc_entity->revision_id = NULL;
$new_fc_entity->is_new = TRUE;
// Set the new entity for saving it later
$entity->{$field_name}[$language][$delta]['entity'] = $new_fc_entity;
}
}
// Check if this field collection item belongs to the source language
if (!isset($field_value['entity'])
&& ($fc_entity = field_collection_field_get_entity($field_value))
&& in_array($fc_entity->item_id, $source_items)) {
// Clone the field collection item
$new_fc_entity = clone $fc_entity;
$new_fc_entity->item_id = NULL;
$new_fc_entity->revision_id = NULL;
$new_fc_entity->is_new = TRUE;
// Set the new entity for saving it later
$entity->{$field_name}[$language][$delta]['entity'] = $new_fc_entity;
}
}
}
......
......@@ -1013,12 +1013,11 @@ class FieldCollectionEntityTranslationTestCase extends DrupalWebTestCase {
$field = field_info_field($field_name);
$field_value = array();
// Copy the value of the translated field if it's translatable.
if ($field['translatable']) {
if (isset($node->{$field_name}[$node->language])) {
$field_value = $node->{$field_name}[$source_langcode];
$values[$field_name][$langcode] = $field_value;
$node->{$field_name}[$langcode] = $field_value;
}
if ($field['translatable']
&& isset($node->{$field_name}[$node->language])) {
$field_value = $node->{$field_name}[$source_langcode];
$values[$field_name][$langcode] = $field_value;
$node->{$field_name}[$langcode] = $field_value;
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment