Commit 1106c7a8 authored by fago's avatar fago
Browse files

#1239946-7 field-collection item double during adding when a field using #ajax is used.

parent 48f7842e
......@@ -169,8 +169,7 @@ class FieldCollectionItemEntity extends Entity {
*
* @param $create_link
* (optional) Whether a field-item linking the host entity to the field
* collection item should be created. Should be only disabled if the link
* is created manually.
* collection item should be created.
*/
public function setHostEntity($entity_type, $entity, $langcode = LANGUAGE_NONE, $create_link = TRUE) {
if (!empty($this->is_new)) {
......
......@@ -124,7 +124,11 @@ function field_collection_item_add($field_name, $entity_type, $entity_id, $revis
drupal_set_title($title);
$field_collection_item = entity_create('field_collection_item', array('field_name' => $field_name));
$field_collection_item->setHostEntity($entity_type, $entity);
// Do not link the field-collection item with the host entity at this point,
// as during the form-workflow we have multiple field-collection item entity
// instances, which we don't want link all with the host.
// That way the link is going to be created when the item is saved.
$field_collection_item->setHostEntity($entity_type, $entity, LANGUAGE_NONE, FALSE);
// Make sure the current user has access to create a field collection item.
if (!field_collection_item_access('create', $field_collection_item)) {
......
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