You are here

protected function FieldCollectionItemEntity::fetchHostDetails in Field collection 7

Collects info about the field collection's host.

Parameters

$hostEntity: The host entity object. (optional)

6 calls to FieldCollectionItemEntity::fetchHostDetails()
FieldCollectionItemEntity::defaultLabel in ./field_collection.entity.inc
Specifies the default label, which is picked up by label() by default.
FieldCollectionItemEntity::hostEntity in ./field_collection.entity.inc
Returns the host entity, which embeds this field collection item.
FieldCollectionItemEntity::hostEntityId in ./field_collection.entity.inc
Returns the id of the host entity, which embeds this field collection item.
FieldCollectionItemEntity::hostEntityType in ./field_collection.entity.inc
Returns the entity type of the host entity, which embeds this field collection item.
FieldCollectionItemEntity::instanceInfo in ./field_collection.entity.inc
Provides info of the field instance containing the reference to this field collection item.

... See full list

File

./field_collection.entity.inc, line 317

Class

FieldCollectionItemEntity
Class for field_collection_item entities.

Code

protected function fetchHostDetails($hostEntity = NULL) {
  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.
      $query = new EntityFieldQuery();
      $field_info = $this
        ->fieldInfo();
      $query
        ->fieldCondition($field_info, 'revision_id', $this->revision_id);
      if ($hostEntity) {
        $entity_type = key($field_info['bundles']);
        $bundle = current($field_info['bundles'][$entity_type]);
        $entity_info = entity_get_info($entity_type);
        $key = $entity_info['entity keys']['id'];
        $query
          ->entityCondition('entity_type', $entity_type);
        $query
          ->entityCondition('entity_id', $hostEntity->{$key});
        $query
          ->entityCondition('bundle', $bundle);

        // Only filter by language if this entity type has a language key that
        // has a corresponding field in its base table.
        if (!empty($entity_info['entity keys']['language']) && !empty($entity_info['schema_fields_sql']['base table']) && in_array($entity_info['entity keys']['language'], $entity_info['schema_fields_sql']['base table'], TRUE)) {
          $query
            ->propertyCondition($entity_info['entity keys']['language'], $hostEntity->{$entity_info['entity keys']['language']});
        }
      }
      $query
        ->addTag('DANGEROUS_ACCESS_CHECK_OPT_OUT');
      if (!$this
        ->isInUse()) {
        $query
          ->age(FIELD_LOAD_REVISION);
      }
      $result = $query
        ->execute();
      if ($result) {
        $this->hostEntityType = key($result);
        $data = current($result);
        if ($this
          ->isInUse()) {
          $data_array_keys = array_keys($data);
          $this->hostEntityId = $data ? end($data_array_keys) : FALSE;
          $this->hostEntityRevisionId = FALSE;
        }
        else {
          $data_array_keys = array_keys($data);
          $this->hostEntityId = FALSE;
          $this->hostEntityRevisionId = $data ? end($data_array_keys) : FALSE;
        }
      }
      else {

        // No host entity available yet.
        $this->hostEntityId = FALSE;
      }
    }
    else {

      // No host entity available yet.
      $this->hostEntityId = FALSE;
    }
  }
  return !empty($this->hostEntityId) || !empty($this->hostEntity) || !empty($this->hostEntityRevisionId);
}