function chado_views_handler_field::post_execute

3.x chado_views_handler_field.inc chado_views_handler_field::post_execute(&$values)

Load the entities for all fields that are about to be displayed.

Notice that, although we load the entities for each chado field, Drupal caches entities to ensure we don't get a performance hit per field, just per row.

File

tripal_chado/views_handlers/chado_views_handler_field.inc, line 43

Class

chado_views_handler_field
Views Field Handler for chado fields. Uses the same approach as the field api views_handler_field_field.

Code

function post_execute(&$values) {
  if (!empty($values) AND isset($this->id_alias) AND isset($this->type_alias)) {

    // Foreach row in the view we want to grab the appropriate entity_id/type.
    $entity_ids = array();
    $keys = array();
    foreach ($values as $key => $object) {
      // Only load the entity if we can access the entity_id.
      if (isset($this->id_alias) AND isset($object->{$this->id_alias})) {
        $entity_ids[$object->{$this->type_alias}][] = $object->{$this->id_alias};
        $keys[$key] = $object->{$this->id_alias};
      }
    }

    // Now load the entities.
    foreach ($entity_ids as $type => $ids) {
      $entities[$type] = entity_load($type, $ids);
    }

    // Finally add the loaded entities and values back into the resultset for easy access.
    foreach ($keys as $row_id => $entity_id) {

      // First set the entities.
      foreach ($entities as $type => $objects) {
        $values[$row_id]->_chado_field_data[$type] = array(
          'entity_type' => $type,
          'entity' => $objects[$entity_id],
        );
      }

      // Then set the value of this field.
      $values[$row_id]->{$this->field_alias} = $this->render_field($objects[$entity_id], $this->definition['field_name'], $row_id);
    }
  }
}