diff --git a/field_collection.entity.inc b/field_collection.entity.inc index 773a3ab..24905de 100644 --- a/field_collection.entity.inc +++ b/field_collection.entity.inc @@ -303,28 +303,26 @@ class FieldCollectionItemEntity extends Entity { protected function fetchHostDetails() { if (!isset($this->hostEntityId) || (!$this->hostEntityId && $this->hostEntityRevisionId)) { if ($this->item_id) { + $in_use = $this->isInUse(); + // For saved field collections, query the field data to determine the // right host entity. $query = new EntityFieldQuery(); $query->fieldCondition($this->fieldInfo(), 'revision_id', $this->revision_id); - if (!$this->isInUse()) { + if (!$in_use) { $query->age(FIELD_LOAD_REVISION); } $result = $query->execute(); - if ($result) { - list($this->hostEntityType, $data) = each($result); - 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 ($result) { + $this->hostEntityType = key($result); + $data = current($result); + end($data); + + // The entity ID or revision ID if we are querying for revisions. + $id = key($data); + $this->hostEntityId = $in_use ? $id : FALSE; + $this->hostEntityRevisionId = $in_use ? FALSE : $id; } else { // No host entity available yet.