Commit c1f704fb authored by moonray's avatar moonray Committed by Joel Muzzerall
Browse files

Issue #2382089 by moonray, ktogias: Fixed a logic issue with...

Issue #2382089 by moonray, ktogias: Fixed a logic issue with fetchHostDetails() causing false "the host entity cannot be changed" error in updateHostEntity()
parent 5e153ae5
......@@ -300,7 +300,7 @@ class FieldCollectionItemEntity extends Entity {
}
protected function fetchHostDetails() {
if (!isset($this->hostEntityId)) {
if (!isset($this->hostEntityId) || (!$this->hostEntityId && $this->hostEntityRevisionId)) {
if ($this->item_id) {
// For saved field collections, query the field data to determine the
// right host entity.
......@@ -310,16 +310,24 @@ class FieldCollectionItemEntity extends Entity {
$query->age(FIELD_LOAD_REVISION);
}
$result = $query->execute();
list($this->hostEntityType, $data) = each($result);
if ($result) {
list($this->hostEntityType, $data) = each($result);
if ($this->isInUse()) {
$this->hostEntityId = $data ? key($data) : FALSE;
$this->hostEntityRevisionId = FALSE;
if ($this->isInUse()) {
$data_array_keys = array_keys($data);
$this->hostEntityId = $data ? end($data_array_keys) : FALSE;
$this->hostEntityRevisionId = FALSE;
}
// If we are querying for revisions, we get the revision ID.
else {
$data_array_keys = array_keys($data);
$this->hostEntityId = FALSE;
$this->hostEntityRevisionId = $data ? end($data_array_keys) : FALSE;
}
}
// If we are querying for revisions, we get the revision ID.
else {
// No host entity available yet.
$this->hostEntityId = FALSE;
$this->hostEntityRevisionId = $data ? key($data) : FALSE;
}
}
else {
......
......@@ -1430,7 +1430,7 @@ function field_collection_remove_submit($form, &$form_state) {
* The entity object or FALSE.
*/
function field_collection_field_get_entity(&$item, $field_name = NULL) {
if (isset($item['entity'])) {
if (isset($item['entity']) && ($item['entity']->entityType() == 'field_collection_item')) {
return $item['entity'];
}
elseif (isset($item['value'])) {
......
Supports Markdown
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