Commit edb4e7d2 authored by berdir's avatar berdir Committed by jmuzz
Browse files

Issue #2013811 by Berdir, deviantintegral, drumm, jmuzz: Fixed bug causing...

Issue #2013811 by Berdir, deviantintegral, drumm, jmuzz: Fixed bug causing host update to drop changes made during save.
parent 6aecbd40
......@@ -331,6 +331,35 @@ class FieldCollectionItemEntity extends Entity {
}
}
/**
* Updates the wrapped host entity object.
*
* @param $entity
*/
public function updateHostEntity($entity) {
$this->fetchHostDetails();
list($recieved_id) = entity_extract_ids($this->hostEntityType, $entity);
if ($this->isInUse()) {
$current_id = $this->hostEntityId;
}
else {
$current_host = entity_revision_load($this->hostEntityType, $this->hostEntityRevisionId);
list($current_id) = entity_extract_ids($this->hostEntityType, $current_host);
}
if ($current_id == $recieved_id) {
$this->hostEntity = $entity;
$delta = $this->delta();
if (isset($entity->{$this->field_name}[$this->langcode][$delta]['entity'])) {
$entity->{$this->field_name}[$this->langcode][$delta]['entity'] = $entity;
}
}
else {
throw new Exception('The host entity cannot be changed.');
}
}
/**
* Returns the host entity, which embeds this field collection item.
*/
......@@ -1003,6 +1032,7 @@ function field_collection_field_update($host_entity_type, $host_entity, $field,
else {
// Delete unused field collection items now.
foreach (field_collection_item_load_multiple($ids) as $un_item) {
$un_item->updateHostEntity($host_entity);
$un_item->deleteRevision(TRUE);
}
}
......
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