You are here

function SarniaViewsHandlerField::post_execute in Sarnia 7

Load any entities that aren't present for use with field formatters, if necessary.

Parameters

$results: An array of views result objects.

Overrides views_handler::post_execute

File

handlers/handler_field.inc, line 219

Class

SarniaViewsHandlerField
Field handler for displaying Solr fields in Views.

Code

function post_execute(&$results) {

  // Don't bother trying to load entities if the formatter doesn't need them.
  if (!empty($this->options['formatter'])) {

    // Get a list of unloaded entities.
    $ids = array();
    foreach ($results as $result_id => $result) {
      $entity_id =& $result->entity;
      if (!is_object($entity_id)) {
        $ids[$result_id] = $entity_id;
      }
    }

    // Load whatever unloaded entities we found.
    if (!empty($ids)) {
      $entities = entity_load($this->sarnia_type_info['machine_name'], array_values($ids));
      foreach ($ids as $result_id => $entity_id) {
        if ($entities[$entity_id]) {
          $results[$result_id]->entity = $entities[$entity_id];
        }
      }
    }
  }
  $this->item_key = 'item__' . $this->options['id'];
  foreach ($results as $row_id => $result) {
    $result->{$this->item_key} = $this
      ->set_items($result, $row_id);
  }
}