From 754e3e853828b12684a9d21d89335257cfdae60d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20Ord=C3=B3=C3=B1ez?= Date: Sun, 6 Nov 2011 04:55:34 +0100 Subject: [PATCH] Issue #1316162: generate separate entities when creating a new translation --- field_collection.module | 20 +++++++++++++++++++- 1 files changed, 19 insertions(+), 1 deletions(-) diff --git a/field_collection.module b/field_collection.module index 9da8350..4fc84b2 100644 --- a/field_collection.module +++ b/field_collection.module @@ -573,6 +573,24 @@ function field_collection_field_presave($entity_type, $entity, $field, $instance if (!empty($item['entity']->is_new)) { $item['entity']->setHostEntity($entity_type, $entity, LANGUAGE_NONE, FALSE); } + else { + if ($entity_type == 'node') { + // reset item_id when it's a new translation + if (!$entity->nid) { + $item['entity']->item_id = ''; + } + else { + $query = new EntityFieldQuery(); + $query->fieldCondition($item['entity']->field_name, 'value', $item['entity']->item_id, '='); + $query->entityCondition('entity_id', $entity->nid, '!='); + $result = $query->execute(); + // reset item_id if exists other node with the same instance + if (!empty($result)) { + $item['entity']->item_id = ''; + } + } + } + } $item['entity']->save(TRUE); $item = array('value' => $item['entity']->item_id); } @@ -1141,4 +1159,4 @@ function field_collection_devel_generate($object, $field, $instance, $bundle) { $field_collection->save(TRUE); return array('value' => $field_collection->item_id); -} +} \ No newline at end of file -- 1.7.6.1