From 6c920c07f75304324fa923a15a29eea1a7b6d8fc Mon Sep 17 00:00:00 2001 From: mordonez Date: Sun, 6 Nov 2011 03:45:44 +0100 Subject: [PATCH] Issue #1316162: generate separate entities when creating a new translation --- field_collection.module | 12 +++++++++++- 1 files changed, 11 insertions(+), 1 deletions(-) diff --git a/field_collection.module b/field_collection.module index 9da8350..1747731 100644 --- a/field_collection.module +++ b/field_collection.module @@ -573,6 +573,16 @@ 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 { + $query = new EntityFieldQuery(); + $query->fieldCondition($item['entity']->field_name, 'value', $item['entity']->item_id, '='); + $query->entityCondition('entity_id', $entity->nid, '!='); + $result = $query->execute(); + // reset the item_id if exists other node with the same instance + if (!empty($result) || empty($entity->nid)) { + $item['entity']->item_id = ''; + } + } $item['entity']->save(TRUE); $item = array('value' => $item['entity']->item_id); } @@ -1141,4 +1151,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