You are here

function _views_xml_render_fields in Views Datasource 7

Same name and namespace in other branches
  1. 6 views_xml.module \_views_xml_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 _views_xml_render_fields()
views_plugin_style_xml::render in views/plugins/views_plugin_style_xml.inc
Implementation of view_style_plugin::render()

File

./views_xml.module, line 111
Module definition for views_xml

Code

function _views_xml_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 = _views_xml_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']) && !empty($field_output) && ($field_output !== "" || $field_output === '0')) {
      $object = new stdClass();
      $object->id = $id;
      $object->content = $field_output;
      $object->raw = $field_raw;
      $object->class = drupal_clean_css_identifier(strtolower($id));
      $object->label = check_plain($view->field[$id]
        ->label());
      $object->is_multiple = $field_is_multiple;
      $rendered_fields[$id] = $object;
    }
  }
  return $rendered_fields;
}