You are here

protected function ParagraphsItemEntity::fetchHostDetails in Paragraphs 7

Fetches details of the host and saves it in the entity.

Return value

bool Whether the fetching was successful.

2 calls to ParagraphsItemEntity::fetchHostDetails()
ParagraphsItemEntity::defaultLabel in ./ParagraphsItemEntity.inc
Specifies the default label, which is picked up by label() by default.
ParagraphsItemEntity::hostEntity in ./ParagraphsItemEntity.inc
Returns the host entity embedding this paragraphs item.

File

./ParagraphsItemEntity.inc, line 279

Class

ParagraphsItemEntity
Entity implementation for the paragraphs entity.

Code

protected function fetchHostDetails() {
  if ($this->fetchedHostEntityDetails === NULL) {
    if ($this->item_id) {

      // For saved paragraphs, query the field data to determine the
      // right host entity.
      $query = new EntityFieldQuery();
      $query
        ->fieldCondition($this
        ->fieldInfo(), 'revision_id', $this->revision_id)
        ->age(FIELD_LOAD_REVISION);
      $result = $query
        ->execute();
      $this->hostEntityType = key($result);
      $data = current($result);
      if ($data) {
        $data_values = array_shift($data);
        $host_entity_info = entity_get_info($this->hostEntityType);
        $host_entity_keys = $host_entity_info['entity keys'];
        $this->hostEntityId = isset($data_values->{$host_entity_keys['id']}) ? $data_values->{$host_entity_keys['id']} : NULL;
        $this->hostEntityRevisionId = isset($data_values->{$host_entity_keys['revision']}) ? $data_values->{$host_entity_keys['revision']} : NULL;
        $this->hostEntityBundle = isset($data_values->{$host_entity_keys['bundle']}) ? $data_values->{$host_entity_keys['bundle']} : NULL;
        $this->hostEntity = entity_revision_load($this->hostEntityType, $this->hostEntityRevisionId);
        $this->fetchedHostEntityDetails = TRUE;
      }
      else {
        $this->hostEntityId = FALSE;
        $this->hostEntityRevisionId = FALSE;
        $this->hostEntityBundle = FALSE;
        $this->fetchedHostEntityDetails = FALSE;
      }
    }
    else {

      // No host entity available yet.
      $this->hostEntityId = FALSE;
      $this->hostEntityRevisionId = FALSE;
      $this->hostEntityBundle = FALSE;
      $this->fetchedHostEntityDetails = FALSE;
    }
  }
  return $this->fetchedHostEntityDetails;
}