You are here

function _search_autocomplete_render_fields in Search Autocomplete 7.3

Same name and namespace in other branches
  1. 7.4 search_autocomplete.view_autocomplete.inc \_search_autocomplete_render_fields()

Takes each field from a row object and renders the field as determined by the field's theme

Parameters

$view: View the row belongs to

$row: Row object

Return value

array Object containing all the raw and rendered fields

1 call to _search_autocomplete_render_fields()
views_plugin_style_autocomplete::render in views/plugins/views_plugin_style_autocomplete.inc
Implements view_style_plugin::render()

File

./search_autocomplete.view_autocomplete.inc, line 148
Search Autocomplete Enables autocomplete functionality on search fields.

Code

function _search_autocomplete_render_fields($view, $row) {
  $field_ids = array_keys($view->field);
  $rendered_fields = array();
  foreach ($field_ids as $id) {
    $field = $view->field[$id];
    $field_is_multiple = FALSE;
    $field_raw = array();
    if (isset($field->options['multiple']['group']) && isset($field->field_values)) {
      $field_output = _search_autocomplete_render_multiple_field($field, $row);
      $n = 0;
      if (is_array($field_output)) {
        foreach ($field->field_values[$row->{$field->field_alias}] as $item) {
          $field_raw[++$n] = $item["value"];
        }
        $field_is_multiple = TRUE;
      }
      else {
        $field_raw = $view->field[$field->options['id']]
          ->advanced_render($row);
      }
    }
    else {
      $field_output = $view->field[$field->options['id']]
        ->advanced_render($row);
      $field_raw = isset($view->field[$id]->field_alias) && isset($row->{$view->field[$id]->field_alias}) ? $row->{$view->field[$id]->field_alias} : NULL;
    }
    $img_match = array();
    $src_match = array();
    if (is_array($field_output)) {
      foreach ($field_output as $i => $f) {
        if (preg_match("/<img[^>]+>/i", $f, $img_match)) {
          if (preg_match('/(src)="([^"]*)"/i', $img_match[0], $src_match)) {
            $field_output[$i] = $src_match[2];
          }
        }
      }
    }
    else {
      if (preg_match("/<img[^>]+>/i", $field_output, $img_match)) {
        if (preg_match('/(src)="([^"]*)"/i', $img_match[0], $src_match)) {
          $field_output = $src_match[2];
        }
      }
    }
    if (empty($field->options['exclude'])) {
      if (empty($field->options['exclude']) && !($field->options['hide_empty'] && empty($field_output))) {
        $object = new stdClass();
        $object->id = $id;

        // Respect the 'empty' value if empty and "No results text" is given.
        if (empty($field_output) && $field->options['empty']) {
          $object->content = $field->options['empty'];
        }
        else {
          $object->content = $field_output;
        }
        $object->raw = $field_raw;
        $object->class = drupal_clean_css_identifier(strtolower($id));

        //views_css_safe($id);
        $object->label = check_plain($view->field[$id]
          ->label());
        if ($object->label) {
          if ($view->field[$id]->options['element_label_colon']) {
            $object->label .= ': ';
          }
          else {
            $object->label .= ' ';
          }
        }
        $object->is_multiple = $field_is_multiple;
        $rendered_fields[$id] = $object;
      }
    }
  }
  return $rendered_fields;
}