You are here

protected function MultifieldEntityController::queryLoad in Multifield 7

Same name and namespace in other branches
  1. 7.2 MultifieldEntityController.php \MultifieldEntityController::queryLoad()
1 call to MultifieldEntityController::queryLoad()
MultifieldEntityController::load in ./MultifieldEntityController.php
Implements DrupalEntityControllerInterface::load().

File

./MultifieldEntityController.php, line 37

Class

MultifieldEntityController

Code

protected function queryLoad($ids) {
  $multifields = multifield_get_fields();
  foreach (array_keys($multifields) as $field_name) {
    $query = new EntityFieldQuery();
    if ($ids) {
      $query
        ->fieldCondition($field_name, 'id', $ids, 'IN');
    }
    else {
      $query
        ->fieldCondition($field_name, 'id', 0, '>');
    }
    if ($results = $query
      ->execute()) {
      $pseudo_entities = array();
      $field = field_info_field($field_name);
      foreach ($results as $entity_type => $entities) {

        // Simply doing an entity load on the entities with multifield values
        // will cause the cacheSet() from multifield_field_load() to get
        // invoked.
        $entities = entity_load($entity_type, array_keys($entities));
        foreach ($entities as $entity) {
          if ($items = field_get_items($entity_type, $entity, $field_name)) {
            foreach ($items as $item) {
              $pseudo_entities[$item['id']] = _multifield_field_item_to_entity($field['type'], $item);
            }
          }
        }
      }
      $this
        ->cacheSet($pseudo_entities);
    }
  }
  return array_intersect_key($this->entityCache, drupal_map_assoc($ids, $ids));
}