You are here

function ip_geoloc_plugin_style_render_fields in IP Geolocation Views & Maps 8

Same name and namespace in other branches
  1. 7 views/ip_geoloc_plugin_style.inc \ip_geoloc_plugin_style_render_fields()

Perform token replacement, convert timestamps to date strings etc.

Store the rendered rows on the object passed in, which will typically be an instance of class views_plugin_style or subclass. Note that fields that have their Exclude box ticked, won't be rendered, Typical candidates for exclusion are the latitude and longitude fields.

Parameters

string $views_plugin_style: The views plugin style.

1 call to ip_geoloc_plugin_style_render_fields()
IpGeoLocPluginStyleOpenLayers::render in src/Plugin/views/style/IpGeoLocPluginStyleOpenLayers.php
Transform the View result in a list of markers and render these on a map.

File

src/Plugin/views/style/ip_geoloc_plugin_style.inc, line 1000
ip_geoloc_plugin_style.inc

Code

function ip_geoloc_plugin_style_render_fields($views_plugin_style) {
  if (!$views_plugin_style
    ->uses_fields() || isset($views_plugin_style->rendered_fields)) {
    return;
  }
  $views_plugin_style->rendered_fields = [];
  $field_ids = array_keys($views_plugin_style->view->field);
  $differentiator = $views_plugin_style->options['differentiator']['differentiator_field'];
  $latitude = trim($views_plugin_style->options['ip_geoloc_views_plugin_latitude']);
  $longitude = trim($views_plugin_style->options['ip_geoloc_views_plugin_longitude']);
  foreach ($views_plugin_style->view->result as $i => &$row) {

    // God knows why we need this...
    $views_plugin_style->view->row_index = $i;
    foreach ($field_ids as $field_id) {
      $field = $views_plugin_style->view->field[$field_id];

      // theme() also renders the tokens that may be used in the balloon fields.
      $field_value = $field
        ->theme($row);

      // Add the special 'views_' fields that normally aren't in the results
      // set to the row, if required for the $differentiator or lat/lon that
      // have math expressions applied through the Views UI.
      $special_field_id = 'views_' . $field_id;
      if (($special_field_id == $differentiator || $special_field_id == $latitude || $special_field_id == $longitude) && empty($row->{$special_field_id})) {
        $row->{$special_field_id}[] = $field_value;
      }

      // If Excluded is ticked, we don't style and add the field to the
      // rendered_fields.
      if (!$field->options['exclude']) {
        $styled_field_value = _ip_geoloc_plugin_style_add_label_and_styling($field, $field_value);
        $views_plugin_style->rendered_fields[$i][$field_id] = $styled_field_value;
      }
    }
  }
  unset($views_plugin_style->view->row_index);
  return $views_plugin_style->rendered_fields;
}