You are here

public function SarniaViewsHandlerField::set_items in Sarnia 7

Extract the field values as an array of items.

Parameters

stdclass $values: A views result.

$row_id: Who knows. <-- @TODO

Return value

array An array of item arrays. Each item array should contain two properties: 'raw': an unfiltered value for use in tokens 'rendered': sanitized rendered HTML for display

1 call to SarniaViewsHandlerField::set_items()
SarniaViewsHandlerField::post_execute in handlers/handler_field.inc
Load any entities that aren't present for use with field formatters, if necessary.

File

handlers/handler_field.inc, line 333

Class

SarniaViewsHandlerField
Field handler for displaying Solr fields in Views.

Code

public function set_items($values, $row_id) {
  $items = array();
  $entity = $values->entity;
  $properties = $values->_entity_properties;
  $solr_property = $this->options['solr_property'];

  // Are we using a Field API field formatter, and is our entity loaded in the results?
  $id_field = $this->sarnia_type_info['id_field'];
  if (!empty($this->options['formatter']) && !empty($entity)) {

    // Build arguments for the Field API field formatter.
    $display = array(
      'type' => $this->options['formatter'],
      'settings' => $this->options['settings'] + array(
        'solr_property' => $solr_property,
      ),
      'label' => 'hidden',
      // Pass the View object in the display so that fields can act on it.
      'views_view' => $this->view,
      'views_field' => $this,
      'views_row_id' => $entity->id,
    );
    $render_array = field_view_field($entity->type, $entity, $this->definition['field_name'], $display, LANGUAGE_NONE);

    // Extract the rendered field values from the render array.
    foreach (element_children($render_array) as $i) {
      $items[$i]['rendered'] = $render_array[$i];
      if (isset($render_array['#access'])) {
        $items[$i]['rendered']['#access'] = $render_array['#access'];
      }
      if ((!isset($items[$i]['rendered']['#access']) || $items[$i]['rendered']['#access']) && !empty($render_array['#items'][$i])) {
        $items[$i]['raw'] = $render_array['#items'][$i];
      }
    }
  }
  else {

    // Return an unprocessed value.
    $value = $this
      ->get_value($values);
    if (is_array($value)) {
      foreach ($properties[$solr_property] as $value) {
        $items[] = array(
          'raw' => $value,
          'rendered' => $this
            ->sanitize_value($value),
        );
      }
    }
    elseif (!empty($value)) {
      $items[] = array(
        'raw' => $properties[$solr_property],
        'rendered' => $this
          ->sanitize_value($properties[$solr_property]),
      );
    }
  }

  // Trim the items based on the multivalue count setting, if present.
  if ($this->options['is_multivalue'] && $this->options['multivalue']['count'] > 0) {
    $items = array_slice($items, 0, $this->options['multivalue']['count']);
  }
  return $items;
}