views.theme.inc 43.4 KB
Newer Older
merlinofchaos's avatar
merlinofchaos committed
1 2 3 4 5 6 7
<?php

/**
 * @file
 * Preprocessors and helper functions to make theming easier.
 */

8
use Drupal\Component\Utility\Xss;
9
use Drupal\Core\Language\Language;
10
use Drupal\Core\Template\Attribute;
11
use Drupal\views\Form\ViewsForm;
12
use Drupal\views\ViewExecutable;
13

merlinofchaos's avatar
merlinofchaos committed
14
/**
15 16 17 18
 * Prepares variables for view templates.
 *
 * Default template: views-view.html.twig.
 *
19
 * @param array $variables
20 21
 *   An associative array containing:
 *   - view: The ViewExecutable object.
merlinofchaos's avatar
merlinofchaos committed
22
 */
23 24
function template_preprocess_views_view(&$variables) {
  $view = $variables['view'];
merlinofchaos's avatar
merlinofchaos committed
25

26
  $variables['rows'] = (!empty($view->result) || $view->style_plugin->evenEmpty()) ? $view->style_plugin->render($view->result) : array();
27
  // Force a render array so CSS/JS can be added.
28 29
  if (!is_array($variables['rows'])) {
    $variables['rows'] = array('#markup' => $variables['rows']);
30
  }
merlinofchaos's avatar
merlinofchaos committed
31

32 33 34
  $variables['css_name'] = drupal_clean_css_identifier($view->storage->id());
  $variables['id'] = $view->storage->id();
  $variables['display_id'] = $view->current_display;
merlinofchaos's avatar
merlinofchaos committed
35

36
  // Basic classes.
37
  $variables['css_class'] = '';
38

39 40 41 42 43
  $variables['attributes']['class'] = array();
  $variables['attributes']['class'][] = 'view';
  $variables['attributes']['class'][] = 'view-' . drupal_clean_css_identifier($variables['id']);
  $variables['attributes']['class'][] = 'view-id-' . $variables['id'];
  $variables['attributes']['class'][] = 'view-display-id-' . $variables['display_id'];
merlinofchaos's avatar
merlinofchaos committed
44

45
  $css_class = $view->display_handler->getOption('css_class');
merlinofchaos's avatar
merlinofchaos committed
46
  if (!empty($css_class)) {
47 48
    $variables['css_class'] = preg_replace('/[^a-zA-Z0-9- ]/', '-', $css_class);
    $variables['attributes']['class'][] = $variables['css_class'];
merlinofchaos's avatar
merlinofchaos committed
49 50
  }

51
  $empty = empty($view->result);
52 53 54
  $variables['header'] = $view->display_handler->renderArea('header', $empty);
  $variables['footer'] = $view->display_handler->renderArea('footer', $empty);
  $variables['empty'] = $empty ? $view->display_handler->renderArea('empty', $empty) : FALSE;
merlinofchaos's avatar
merlinofchaos committed
55

56 57 58
  $variables['exposed']    = !empty($view->exposed_widgets) ? $view->exposed_widgets : '';
  $variables['more']       = $view->display_handler->renderMoreLink();
  $variables['feed_icon']  = !empty($view->feed_icon) ? $view->feed_icon : '';
merlinofchaos's avatar
merlinofchaos committed
59

60
  $variables['pager']      = '';
merlinofchaos's avatar
merlinofchaos committed
61 62 63

  // @todo: Figure out whether this belongs into views_ui_preprocess_views_view.
  // Render title for the admin preview.
64
  $variables['title'] = !empty($view->views_ui_context) ? filter_xss_admin($view->getTitle()) : '';
merlinofchaos's avatar
merlinofchaos committed
65

66
  if ($view->display_handler->renderPager()) {
merlinofchaos's avatar
merlinofchaos committed
67
    $exposed_input = isset($view->exposed_raw_input) ? $view->exposed_raw_input : NULL;
68
    $variables['pager'] = $view->renderPager($exposed_input);
merlinofchaos's avatar
merlinofchaos committed
69 70
  }

71
  if (!empty($view->attachment_before)) {
72
    $variables['attachment_before'] = $view->attachment_before;
73 74
  }
  else {
75
    $variables['attachment_before'] = array();
76 77
  }
  if (!empty($view->attachment_after)) {
78
    $variables['attachment_after'] = $view->attachment_after;
79 80
  }
  else {
81
    $variables['attachment_after'] = array();
82
  }
merlinofchaos's avatar
merlinofchaos committed
83 84 85 86 87 88

  // Add contextual links to the view. We need to attach them to the dummy
  // $view_array variable, since contextual_preprocess() requires that they be
  // attached to an array (not an object) in order to process them. For our
  // purposes, it doesn't matter what we attach them to, since once they are
  // processed by contextual_preprocess() they will appear in the $title_suffix
89
  // variable (which we will then render in views-view.html.twig).
90
  views_add_contextual_links($variables['view_array'], 'view', $view, $view->current_display);
merlinofchaos's avatar
merlinofchaos committed
91 92 93 94

  // Attachments are always updated with the outer view, never by themselves,
  // so they do not have dom ids.
  if (empty($view->is_attachment)) {
95 96
    // Our JavaScript needs to have some means to find the HTML belonging to
    // this view.
merlinofchaos's avatar
merlinofchaos committed
97 98 99 100
    //
    // It is true that the DIV wrapper has classes denoting the name of the view
    // and its display ID, but this is not enough to unequivocally match a view
    // with its HTML, because one view may appear several times on the page. So
101 102
    // we set up a hash with the current time, $dom_id, to issue a "unique"
    // identifier for each view. This identifier is written to both
103
    // drupalSettings and the DIV wrapper.
104 105
    $variables['dom_id'] = $view->dom_id;
    $variables['attributes']['class'][] = 'view-dom-id-' . $variables['dom_id'];
merlinofchaos's avatar
merlinofchaos committed
106 107 108
  }

  // If using AJAX, send identifying data about this view.
109
  if ($view->ajaxEnabled() && empty($view->is_attachment) && empty($view->live_preview)) {
merlinofchaos's avatar
merlinofchaos committed
110 111 112 113
    $settings = array(
      'views' => array(
        'ajax_path' => url('views/ajax'),
        'ajaxViews' => array(
114
          'views_dom_id:' . $variables['dom_id'] => array(
115
            'view_name' => $view->storage->id(),
merlinofchaos's avatar
merlinofchaos committed
116 117
            'view_display_id' => $view->current_display,
            'view_args' => check_plain(implode('/', $view->args)),
118
            'view_path' => check_plain(current_path()),
119
            'view_base_path' => $view->getPath(),
120
            'view_dom_id' => $variables['dom_id'],
merlinofchaos's avatar
merlinofchaos committed
121 122
            // To fit multiple views on a page, the programmer may have
            // overridden the display's pager_element.
123
            'pager_element' => isset($view->pager) ? $view->pager->getPagerId() : 0,
merlinofchaos's avatar
merlinofchaos committed
124 125 126 127
          ),
        ),
      ),
    );
128 129
    $view->element['#attached']['js'][] = array('type' => 'setting', 'data' => $settings);
    $view->element['#attached']['library'][] = array('views', 'views.ajax');
merlinofchaos's avatar
merlinofchaos committed
130 131
  }

132
  // If form fields were found in the view, reformat the view output as a form.
merlinofchaos's avatar
merlinofchaos committed
133
  if (views_view_has_form_elements($view)) {
134
    // Copy the rows so as not to modify them by reference when rendering.
135
    $rows = $variables['rows'];
136
    $rows = drupal_render($rows);
137
    $output = !empty($rows) ? $rows : $variables['empty'];
138 139 140 141

    $container = \Drupal::getContainer();
    $form_object = new ViewsForm($container->get('controller_resolver'), $container->get('url_generator'), $container->get('request'), $view->storage->id(), $view->current_display);
    $form = \Drupal::formBuilder()->getForm($form_object, $view, $output);
merlinofchaos's avatar
merlinofchaos committed
142 143 144
    // The form is requesting that all non-essential views elements be hidden,
    // usually because the rendered step is not a view result.
    if ($form['show_view_elements']['#value'] == FALSE) {
145 146 147 148 149 150
      $variables['header'] = '';
      $variables['exposed'] = '';
      $variables['pager'] = '';
      $variables['footer'] = '';
      $variables['more'] = '';
      $variables['feed_icon'] = '';
merlinofchaos's avatar
merlinofchaos committed
151
    }
152
    $variables['rows'] = $form;
merlinofchaos's avatar
merlinofchaos committed
153 154 155 156
  }
}

/**
157 158 159 160
 * Prepares variables for views fields templates.
 *
 * Default template: views-view-fields.html.twig.
 *
161
 * @param array $variables
162 163 164 165 166 167 168 169 170 171 172 173
 *   An associative array containing:
 *   - view: The view object.
 *   - options: An array of options. Each option contains:
 *     - inline: An array that contains the fields that are to be
 *       displayed inline.
 *     - default_field_elements: If default field wrapper
 *       elements are to be provided.
 *     - hide_empty: Whether the field is to be hidden if empty.
 *     - element_default_classes: If the default classes are to be added.
 *     - separator: A string to be placed between inline fields to keep them
 *       visually distinct.
 *    - row: An array containing information about the current row.
merlinofchaos's avatar
merlinofchaos committed
174
 */
175 176
function template_preprocess_views_view_fields(&$variables) {
  $view = $variables['view'];
merlinofchaos's avatar
merlinofchaos committed
177 178 179

  // Loop through the fields for this view.
  $previous_inline = FALSE;
180
  $variables['fields'] = array(); // ensure it's at least an empty array.
merlinofchaos's avatar
merlinofchaos committed
181 182
  foreach ($view->field as $id => $field) {
    // render this even if set to exclude so it can be used elsewhere.
183
    $field_output = $view->style_plugin->getField($view->row_index, $id);
184
    $empty = $field->isValueEmpty($field_output, $field->options['empty_zero']);
185
    if (empty($field->options['exclude']) && (!$empty || (empty($field->options['hide_empty']) && empty($variables['options']['hide_empty'])))) {
merlinofchaos's avatar
merlinofchaos committed
186
      $object = new stdClass();
187
      $object->handler = $view->field[$id];
188
      $object->inline = !empty($variables['options']['inline'][$id]);
merlinofchaos's avatar
merlinofchaos committed
189

190
      $object->element_type = $object->handler->elementType(TRUE, !$variables['options']['default_field_elements'], $object->inline);
merlinofchaos's avatar
merlinofchaos committed
191
      if ($object->element_type) {
192
        $attributes = array();
merlinofchaos's avatar
merlinofchaos committed
193
        if ($object->handler->options['element_default_classes']) {
194
          $attributes['class'][] = 'field-content';
merlinofchaos's avatar
merlinofchaos committed
195 196
        }

197
        if ($classes = $object->handler->elementClasses($view->row_index)) {
198
          $attributes['class'][] = $classes;
merlinofchaos's avatar
merlinofchaos committed
199
        }
200
        $attributes = new Attribute($attributes);
merlinofchaos's avatar
merlinofchaos committed
201 202

        $pre = '<' . $object->element_type;
203
        $pre .= $attributes;
merlinofchaos's avatar
merlinofchaos committed
204 205 206 207 208 209 210 211 212 213
        $field_output = $pre . '>' . $field_output . '</' . $object->element_type . '>';
      }

      // Protect ourself somewhat for backward compatibility. This will prevent
      // old templates from producing invalid HTML when no element type is selected.
      if (empty($object->element_type)) {
        $object->element_type = 'span';
      }

      $object->content = $field_output;
214 215
      if (isset($view->field[$id]->field_alias) && isset($variables['row']->{$view->field[$id]->field_alias})) {
        $object->raw = $variables['row']->{$view->field[$id]->field_alias};
merlinofchaos's avatar
merlinofchaos committed
216 217 218 219 220
      }
      else {
        $object->raw = NULL; // make sure it exists to reduce NOTICE
      }

221 222
      if (!empty($variables['options']['separator']) && $previous_inline && $object->inline && $object->content) {
        $object->separator = filter_xss_admin($variables['options']['separator']);
merlinofchaos's avatar
merlinofchaos committed
223 224 225 226 227
      }

      $object->class = drupal_clean_css_identifier($id);

      $previous_inline = $object->inline;
228
      $object->inline_html = $object->handler->elementWrapperType(TRUE, TRUE);
229
      if ($object->inline_html === '' && $variables['options']['default_field_elements']) {
merlinofchaos's avatar
merlinofchaos committed
230 231 232 233 234 235 236 237
        $object->inline_html = $object->inline ? 'span' : 'div';
      }

      // Set up the wrapper HTML.
      $object->wrapper_prefix = '';
      $object->wrapper_suffix = '';

      if ($object->inline_html) {
238
        $attributes = array();
merlinofchaos's avatar
merlinofchaos committed
239
        if ($object->handler->options['element_default_classes']) {
240 241
          $attributes['class'][] = 'views-field';
          $attributes['class'][] = 'views-field-' . $object->class;
merlinofchaos's avatar
merlinofchaos committed
242 243
        }

244
        if ($classes = $object->handler->elementWrapperClasses($view->row_index)) {
245
          $attributes['class'][] = $classes;
merlinofchaos's avatar
merlinofchaos committed
246
        }
247
        $attributes = new Attribute($attributes);
merlinofchaos's avatar
merlinofchaos committed
248 249

        $object->wrapper_prefix = '<' . $object->inline_html;
250
        $object->wrapper_prefix .= $attributes;
merlinofchaos's avatar
merlinofchaos committed
251 252 253 254 255 256 257 258 259 260 261 262 263 264
        $object->wrapper_prefix .= '>';
        $object->wrapper_suffix = '</' . $object->inline_html . '>';
      }

      // Set up the label for the value and the HTML to make it easier
      // on the template.
      $object->label = check_plain($view->field[$id]->label());
      $object->label_html = '';
      if ($object->label) {
        $object->label_html .= $object->label;
        if ($object->handler->options['element_label_colon']) {
          $object->label_html .= ': ';
        }

265
        $object->elementLabelType = $object->handler->elementLabelType(TRUE, !$variables['options']['default_field_elements']);
266
        if ($object->elementLabelType) {
267
          $attributes = array();
merlinofchaos's avatar
merlinofchaos committed
268
          if ($object->handler->options['element_default_classes']) {
269 270
            $attributes['class'][] = 'views-label';
            $attributes['class'][] = 'views-label-' . $object->class;
merlinofchaos's avatar
merlinofchaos committed
271 272
          }

273
          $element_label_class = $object->handler->elementLabelClasses($view->row_index);
merlinofchaos's avatar
merlinofchaos committed
274
          if ($element_label_class) {
275
            $attributes['class'][] = $element_label_class;
merlinofchaos's avatar
merlinofchaos committed
276
          }
277
          $attributes = new Attribute($attributes);
merlinofchaos's avatar
merlinofchaos committed
278

279
          $pre = '<' . $object->elementLabelType;
280
          $pre .= $attributes;
merlinofchaos's avatar
merlinofchaos committed
281 282
          $pre .= '>';

283
          $object->label_html = $pre . $object->label_html . '</' . $object->elementLabelType . '>';
merlinofchaos's avatar
merlinofchaos committed
284 285 286
        }
      }

287
      $variables['fields'][$id] = $object;
merlinofchaos's avatar
merlinofchaos committed
288 289 290 291 292
    }
  }

}

293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310
/**
* Returns HTML for multiple views fields.
*
* @param $variables
*   An associative array containing:
*   - fields: An array of field objects. Each field object contains:
*     - separator: A string that separates the fields.
*     - wrapper_suffix: A string added to the beginning of the fields.
*     - label_html: An HTML string that labels the fields.
*     - content: The fields.
*     - wrapper_suffix: A string added to the end of the fields.
*
* @see template_preprocess_views_view_fields()
*/
function theme_views_view_fields($variables) {
  $fields = $variables['fields'];
  $output = '';

311
  foreach ($fields as $field) {
312 313 314 315 316 317 318 319 320 321 322 323 324 325
    if (!empty($field->separator)) {
      $output .= $field->separator;
    }

    $output .= $field->wrapper_prefix;
    $output .= $field->label_html;
    $output .= $field->content;

    $output .= $field->wrapper_suffix;
  }

  return $output;
}

merlinofchaos's avatar
merlinofchaos committed
326
/**
327 328 329 330
 * Prepares variables for views single grouping templates.
 *
 * Default template: views-view-grouping.html.twig.
 *
331
 * @param array $variables
332 333 334 335 336 337 338 339
 *   An associative array containing:
 *   - view: The view object.
 *   - rows: The rows returned from the view.
 *   - grouping_level: Integer indicating the hierarchical level of the
 *     grouping.
 *   - content: The content to be grouped.
 *   - title: The group heading.
  */
340 341
function template_preprocess_views_view_grouping(&$variables) {
  $variables['content'] = $variables['view']->style_plugin->renderGroupingSets($variables['rows'], $variables['grouping_level']);
merlinofchaos's avatar
merlinofchaos committed
342 343 344 345 346 347 348 349 350
}

/**
 * Display a single views field.
 *
 * Interesting bits of info:
 * $field->field_alias says what the raw value in $row will be. Reach it like
 * this: @code { $row->{$field->field_alias} @endcode
 */
351 352
function theme_views_view_field($variables) {
  return $variables['output'];
merlinofchaos's avatar
merlinofchaos committed
353 354 355
}

/**
356
 * Prepares variables for views field templates.
merlinofchaos's avatar
merlinofchaos committed
357
 *
358 359
 * Default template: views-view-field.html.twig.
 *
360
 * @param array $variables
361 362 363 364 365
 *   An associative array containing:
 *   - field: The field handler object for the current field.
 *   - row: Object representing the raw result of the SQL query for the current
 *     field.
 *   - view: Instance of the ViewExecutable object for the parent view.
merlinofchaos's avatar
merlinofchaos committed
366
 */
367 368
function template_preprocess_views_view_field(&$variables) {
  $variables['output'] = $variables['field']->advancedRender($variables['row']);
merlinofchaos's avatar
merlinofchaos committed
369 370 371
}

/**
372 373 374 375 376 377
 * Prepares variables for views summary templates.
 *
 * The summary prints a single record from a row, with fields.
 *
 * Default template: views-view-summary.html.twig.
 *
378
 * @param array $variables
379 380 381
 *   An associative array containing:
 *   - view: A ViewExecutable object.
 *   - rows: The raw row data.
merlinofchaos's avatar
merlinofchaos committed
382
 */
383 384
function template_preprocess_views_view_summary(&$variables) {
  $view = $variables['view'];
merlinofchaos's avatar
merlinofchaos committed
385 386 387 388 389 390 391 392 393
  $argument = $view->argument[$view->build_info['summary_level']];

  $url_options = array();

  if (!empty($view->exposed_raw_input)) {
    $url_options['query'] = $view->exposed_raw_input;
  }

  $active_urls = drupal_map_assoc(array(
394 395
    url(current_path(), array('alias' => TRUE)), // force system path
    url(current_path()), // could be an alias
merlinofchaos's avatar
merlinofchaos committed
396 397
  ));

398 399 400
  // Collect all arguments foreach row, to be able to alter them for example
  // by the validator. This is not done per single argument value, because this
  // could cause performance problems.
merlinofchaos's avatar
merlinofchaos committed
401 402
  $row_args = array();

403
  foreach ($variables['rows'] as $id => $row) {
404
    $row_args[$id] = $argument->summaryArgument($row);
merlinofchaos's avatar
merlinofchaos committed
405
  }
406
  $argument->processSummaryArguments($row_args);
merlinofchaos's avatar
merlinofchaos committed
407

408
  foreach ($variables['rows'] as $id => $row) {
409
    $variables['rows'][$id]->attributes = array();
410
    $variables['rows'][$id]->link = $argument->summaryName($row);
merlinofchaos's avatar
merlinofchaos committed
411 412 413 414 415 416 417
    $args = $view->args;
    $args[$argument->position] = $row_args[$id];

    $base_path = NULL;
    if (!empty($argument->options['summary_options']['base_path'])) {
      $base_path = $argument->options['summary_options']['base_path'];
    }
418 419 420
    $variables['rows'][$id]->url = url($view->getUrl($args, $base_path), $url_options);
    $variables['rows'][$id]->count = intval($row->{$argument->count_alias});
    if (isset($active_urls[$variables['rows'][$id]->url])) {
421
      $variables['rows'][$id]->attributes['class'][] = 'active';
merlinofchaos's avatar
merlinofchaos committed
422
    }
423
    $variables['rows'][$id]->attributes = new Attribute($variables['rows'][$id]->attributes);
merlinofchaos's avatar
merlinofchaos committed
424 425 426 427
  }
}

/**
428 429 430 431
 * Prepares variables for unformatted summary view templates.
 *
 * Default template: views-view-summary-unformatted.html.twig.
 *
432
 * @param array $variables
433 434 435 436 437 438
 *   An associative array containing:
 *   - view: A ViewExecutable object.
 *   - rows: The raw row data.
 *   - options: An array of options. Each option contains:
 *     - separator: A string to be placed between inline fields to keep them
 *       visually distinct.
merlinofchaos's avatar
merlinofchaos committed
439
 */
440 441
function template_preprocess_views_view_summary_unformatted(&$variables) {
  $view = $variables['view'];
merlinofchaos's avatar
merlinofchaos committed
442 443 444 445 446 447 448 449 450 451
  $argument = $view->argument[$view->build_info['summary_level']];

  $url_options = array();

  if (!empty($view->exposed_raw_input)) {
    $url_options['query'] = $view->exposed_raw_input;
  }

  $count = 0;
  $active_urls = drupal_map_assoc(array(
452 453 454 455
    // Force system path.
    url(current_path(), array('alias' => TRUE)),
    // Could be an alias.
    url(current_path()),
merlinofchaos's avatar
merlinofchaos committed
456 457
  ));

458 459 460
  // Collect all arguments for each row, to be able to alter them for example
  // by the validator. This is not done per single argument value, because
  // this could cause performance problems.
merlinofchaos's avatar
merlinofchaos committed
461
  $row_args = array();
462
  foreach ($variables['rows'] as $id => $row) {
463
    $row_args[$id] = $argument->summaryArgument($row);
merlinofchaos's avatar
merlinofchaos committed
464
  }
465
  $argument->processSummaryArguments($row_args);
merlinofchaos's avatar
merlinofchaos committed
466

467
  foreach ($variables['rows'] as $id => $row) {
468
    // Only false on first time.
merlinofchaos's avatar
merlinofchaos committed
469
    if ($count++) {
470
      $variables['rows'][$id]->separator = filter_xss_admin($variables['options']['separator']);
merlinofchaos's avatar
merlinofchaos committed
471
    }
472
    $variables['rows'][$id]->attributes = array();
473
    $variables['rows'][$id]->link = $argument->summaryName($row);
merlinofchaos's avatar
merlinofchaos committed
474 475 476 477 478 479 480
    $args = $view->args;
    $args[$argument->position] = $row_args[$id];

    $base_path = NULL;
    if (!empty($argument->options['summary_options']['base_path'])) {
      $base_path = $argument->options['summary_options']['base_path'];
    }
481 482 483
    $variables['rows'][$id]->url = url($view->getUrl($args, $base_path), $url_options);
    $variables['rows'][$id]->count = intval($row->{$argument->count_alias});
    if (isset($active_urls[$variables['rows'][$id]->url])) {
484
      $variables['rows'][$id]->attributes['class'][] = 'active';
merlinofchaos's avatar
merlinofchaos committed
485
    }
486
    $variables['rows'][$id]->attributes = new Attribute($variables['rows'][$id]->attributes);
merlinofchaos's avatar
merlinofchaos committed
487 488 489 490
  }
}

/**
491 492 493 494
 * Prepares variables for views table templates.
 *
 * Default template: views-view-table.html.twig.
 *
495
 * @param array $variables
496 497 498
 *   An associative array containing:
 *   - view: A ViewExecutable object.
 *   - rows: The raw row data.
merlinofchaos's avatar
merlinofchaos committed
499
 */
500 501
function template_preprocess_views_view_table(&$variables) {
  $view = $variables['view'];
merlinofchaos's avatar
merlinofchaos committed
502

503
  // We need the raw data for this grouping, which is passed in
504
  // as $variables['rows'].
merlinofchaos's avatar
merlinofchaos committed
505
  // However, the template also needs to use for the rendered fields.  We
506
  // therefore swap the raw data out to a new variable and reset $variables['rows']
merlinofchaos's avatar
merlinofchaos committed
507 508
  // so that it can get rebuilt.
  // Store rows so that they may be used by further preprocess functions.
509 510 511
  $result = $variables['result'] = $variables['rows'];
  $variables['rows'] = array();
  $variables['header'] = array();
merlinofchaos's avatar
merlinofchaos committed
512

513 514
  $options = $view->style_plugin->options;
  $handler = $view->style_plugin;
merlinofchaos's avatar
merlinofchaos committed
515 516 517

  $row_class_special = isset($options['row_class_special']) ? $options['row_class_special'] : TRUE;

518
  $fields = &$view->field;
519
  $columns = $handler->sanitizeColumns($options['columns'], $fields);
merlinofchaos's avatar
merlinofchaos committed
520

521 522
  $active = !empty($handler->active) ? $handler->active : '';
  $order = !empty($handler->order) ? $handler->order : 'asc';
merlinofchaos's avatar
merlinofchaos committed
523

524 525 526
  // A boolean variable which stores whether the table has a responsive class.
  $responsive = FALSE;

527
  $query = tablesort_get_query_parameters();
merlinofchaos's avatar
merlinofchaos committed
528 529 530 531
  if (isset($view->exposed_raw_input)) {
    $query += $view->exposed_raw_input;
  }

532 533
  // A boolean to store whether the table's header has any labels.
  $has_header_labels = FALSE;
merlinofchaos's avatar
merlinofchaos committed
534
  foreach ($columns as $field => $column) {
535 536
    // Create a second variable so we can easily find what fields we have and
    // what the CSS classes should be.
537
    $variables['fields'][$field] = drupal_clean_css_identifier($field);
merlinofchaos's avatar
merlinofchaos committed
538
    if ($active == $field) {
539
      $variables['fields'][$field] .= ' active';
merlinofchaos's avatar
merlinofchaos committed
540 541
    }

542
    // Render the header labels.
merlinofchaos's avatar
merlinofchaos committed
543 544
    if ($field == $column && empty($fields[$field]->options['exclude'])) {
      $label = check_plain(!empty($fields[$field]) ? $fields[$field]->label() : '');
545
      if (empty($options['info'][$field]['sortable']) || !$fields[$field]->clickSortable()) {
546
        $variables['header'][$field]['content'] = $label;
merlinofchaos's avatar
merlinofchaos committed
547 548 549 550 551 552 553 554 555 556
      }
      else {
        $initial = !empty($options['info'][$field]['default_sort_order']) ? $options['info'][$field]['default_sort_order'] : 'asc';

        if ($active == $field) {
          $initial = ($order == 'asc') ? 'desc' : 'asc';
        }

        $title = t('sort by @s', array('@s' => $label));
        if ($active == $field) {
557 558 559 560 561
          $tablesort_indicator = array(
            '#theme' => 'tablesort_indicator',
            '#style' => $initial,
          );
          $label .= drupal_render($tablesort_indicator);
merlinofchaos's avatar
merlinofchaos committed
562 563 564 565 566 567 568 569 570
        }

        $query['order'] = $field;
        $query['sort'] = $initial;
        $link_options = array(
          'html' => TRUE,
          'attributes' => array('title' => $title),
          'query' => $query,
        );
571
        $variables['header'][$field]['content'] = l($label, current_path(), $link_options);
merlinofchaos's avatar
merlinofchaos committed
572 573 574
      }

      // Set up the header label class.
575
      $variables['header'][$field]['attributes'] = array();
merlinofchaos's avatar
merlinofchaos committed
576
      if ($fields[$field]->options['element_default_classes']) {
577 578
        $variables['header'][$field]['attributes']['class'][] = 'views-field';
        $variables['header'][$field]['attributes']['class'][] = 'views-field-' . $variables['fields'][$field];
merlinofchaos's avatar
merlinofchaos committed
579
      }
580
      $class = $fields[$field]->elementLabelClasses(0);
merlinofchaos's avatar
merlinofchaos committed
581
      if ($class) {
582
        $variables['header'][$field]['attributes']['class'][] = $class;
merlinofchaos's avatar
merlinofchaos committed
583
      }
584 585
      // Add responsive header classes.
      if (!empty($options['info'][$field]['responsive'])) {
586
        $variables['header'][$field]['attributes']['class'][] = $options['info'][$field]['responsive'];
587 588
        $responsive = TRUE;
      }
589
      // Add a CSS align class to each field if one was set.
merlinofchaos's avatar
merlinofchaos committed
590
      if (!empty($options['info'][$field]['align'])) {
591
        $variables['header'][$field]['attributes']['class'][] = drupal_clean_css_identifier($options['info'][$field]['align']);
merlinofchaos's avatar
merlinofchaos committed
592 593
      }
      // Add a header label wrapper if one was selected.
594
      if ($variables['header'][$field]['content']) {
595
        $element_label_type = $fields[$field]->elementLabelType(TRUE, TRUE);
merlinofchaos's avatar
merlinofchaos committed
596
        if ($element_label_type) {
597
          $variables['header'][$field]['content'] = '<' . $element_label_type . '>' . $variables['header'][$field]['content'] . '</' . $element_label_type . '>';
merlinofchaos's avatar
merlinofchaos committed
598
        }
599
        // Improves accessibility of complex tables.
600
        $variables['header'][$field]['attributes']['id'] = drupal_html_id('view-' . $field . '-table-column');
merlinofchaos's avatar
merlinofchaos committed
601
      }
602 603 604 605 606 607
      // Check if header label is not empty.
      if (!empty($variables['header'][$field]['content'])) {
        $has_header_labels = TRUE;
      }

      $variables['header'][$field]['attributes'] = new Attribute($variables['header'][$field]['attributes']);
merlinofchaos's avatar
merlinofchaos committed
608 609
    }

610
    // Add a CSS align class to each field if one was set.
merlinofchaos's avatar
merlinofchaos committed
611
    if (!empty($options['info'][$field]['align'])) {
612
      $variables['fields'][$field] .= ' ' . drupal_clean_css_identifier($options['info'][$field]['align']);
merlinofchaos's avatar
merlinofchaos committed
613 614 615 616
    }

    // Render each field into its appropriate column.
    foreach ($result as $num => $row) {
617 618 619 620 621 622 623 624 625 626

      // Skip building the attributes and content if the field is to be excluded
      // from the display.
      if (!empty($fields[$field]->options['exclude'])) {
        continue;
      }

      // Reference to the column in the loop to make the code easier to read.
      $column_reference =& $variables['rows'][$num]['columns'][$column];

627
      // Add field classes.
628
      $column_reference['attributes'] = array();
merlinofchaos's avatar
merlinofchaos committed
629
      if ($fields[$field]->options['element_default_classes']) {
630 631
        $column_reference['attributes']['class'][] = 'views-field';
        $column_reference['attributes']['class'][] = 'views-field-' . $variables['fields'][$field];
merlinofchaos's avatar
merlinofchaos committed
632 633
      }

634
      if ($classes = $fields[$field]->elementClasses($num)) {
635
        $column_reference['attributes']['class'][] = $classes;
merlinofchaos's avatar
merlinofchaos committed
636
      }
637

638 639
      // Add responsive header classes.
      if (!empty($options['info'][$field]['responsive'])) {
640
        $column_reference['attributes']['class'][] = $options['info'][$field]['responsive'];
641 642
      }

643
      // Improves accessibility of complex tables.
644
      if (isset($variables['header'][$field]['attributes']['id'])) {
645
        $column_reference['attributes']['headers'] = array($variables['header'][$field]['attributes']['id']);
646 647
      }

648
      if (!empty($fields[$field])) {
649
        $field_output = $handler->getField($num, $field);
650
        $element_type = $fields[$field]->elementType(TRUE, TRUE);
merlinofchaos's avatar
merlinofchaos committed
651 652 653 654
        if ($element_type) {
          $field_output = '<' . $element_type . '>' . $field_output . '</' . $element_type . '>';
        }

655
        // Only bother with separators and stuff if the field shows up.
656
        if (!empty($field_output) && empty($column_reference['content'])) {
657
          // Place the field into the column, along with an optional separator.
658
          if (!empty($column_reference['content'])) {
659
            if (!empty($options['info'][$column]['separator'])) {
660
              $column_reference['content'] .= filter_xss_admin($options['info'][$column]['separator']);
661
            }
merlinofchaos's avatar
merlinofchaos committed
662
          }
663
          else {
664
            $column_reference['content'] = '';
665
          }
666
          $column_reference['content'] .= $field_output;
merlinofchaos's avatar
merlinofchaos committed
667 668
        }
      }
669
      $column_reference['attributes'] = new Attribute($column_reference['attributes']);
merlinofchaos's avatar
merlinofchaos committed
670 671
    }

672 673
    // Remove columns if the option is hide empty column is checked and the
    // field is not empty.
merlinofchaos's avatar
merlinofchaos committed
674 675
    if (!empty($options['info'][$field]['empty_column'])) {
      $empty = TRUE;
676
      foreach ($variables['rows'] as $columns) {
merlinofchaos's avatar
merlinofchaos committed
677 678 679
        $empty &= empty($columns[$column]);
      }
      if ($empty) {
680
        foreach ($variables['rows'] as &$column_items) {
merlinofchaos's avatar
merlinofchaos committed
681
          unset($column_items[$column]);
682
          unset($variables['header'][$column]);
merlinofchaos's avatar
merlinofchaos committed
683 684 685 686 687 688
        }
      }
    }
  }

  // Hide table header if all labels are empty.
689
  if (!$has_header_labels) {
690
    $variables['header'] = array();
merlinofchaos's avatar
merlinofchaos committed
691 692 693
  }

  $count = 0;
694
  foreach ($variables['rows'] as $num => $row) {
695
    $variables['rows'][$num]['attributes'] = array();
merlinofchaos's avatar
merlinofchaos committed
696
    if ($row_class_special) {
697
      $variables['rows'][$num]['attributes']['class'][] = ($count++ % 2 == 0) ? 'odd' : 'even';
698
      if ($num === 0) {
699
        $variables['rows'][$num]['attributes']['class'][] = 'views-row-first';
700
      }
701
      elseif ($num === (count($variables['rows']) - 1)) {
702
        $variables['rows'][$num]['attributes']['class'][] = 'views-row-last';
703
      }
merlinofchaos's avatar
merlinofchaos committed
704
    }
705
    if ($row_class = $handler->getRowClass($num)) {
706
      $variables['rows'][$num]['attributes']['class'][] = $row_class;
merlinofchaos's avatar
merlinofchaos committed
707
    }
708
    $variables['rows'][$num]['attributes'] = new Attribute($variables['rows'][$num]['attributes']);
merlinofchaos's avatar
merlinofchaos committed
709 710
  }

711 712 713
  $variables['attributes']['class'][] = 'views-table';
  $variables['attributes']['class'][] = 'views-view-table';
  if (empty($variables['rows']) && !empty($options['empty_table'])) {
714
    $build = $view->display_handler->renderArea('empty');
715 716
    $variables['rows'][0]['columns'][0]['content'] = drupal_render($build);
    $variables['rows'][0]['attributes'] = new Attribute(array('class' => 'odd'));
merlinofchaos's avatar
merlinofchaos committed
717
    // Calculate the amounts of rows with output.
718
    $variables['rows'][0]['columns'][0]['attributes'] = new Attribute(array(
719
      'colspan' => count($variables['header']),
720 721
      'class' => 'views-empty',
    ));
merlinofchaos's avatar
merlinofchaos committed
722 723 724
  }

  if (!empty($options['sticky'])) {
725 726
    $variables['view']->element['#attached']['library'][] = array('system', 'drupal.tableheader');
    $variables['attributes']['class'][] = "sticky-enabled";
merlinofchaos's avatar
merlinofchaos committed
727
  }
728
  $variables['attributes']['class'][] = 'cols-' . count($variables['header']);
merlinofchaos's avatar
merlinofchaos committed
729

730 731
  // Add the caption to the list if set.
  if (!empty($handler->options['caption'])) {
732 733
    $variables['caption'] = Xss::filterAdmin($handler->options['caption']);
    $variables['caption_needed'] = TRUE;
merlinofchaos's avatar
merlinofchaos committed
734
  }
735
  else {
736 737
    $variables['caption'] = '';
    $variables['caption_needed'] = FALSE;
738 739
  }

740 741 742
  $variables['summary'] = $handler->options['summary'];
  $variables['description'] = $handler->options['description'];
  $variables['caption_needed'] |= !empty($variables['summary']) || !empty($variables['description']);
743

744 745 746
  // If the table has headers and it should react responsively to columns hidden
  // with the classes represented by the constants RESPONSIVE_PRIORITY_MEDIUM
  // and RESPONSIVE_PRIORITY_LOW, add the tableresponsive behaviors.
747 748
  if (isset($variables['header']) && $responsive) {
    $variables['view']->element['#attached']['library'][] = array('system', 'drupal.tableresponsive');
749 750
    // Add 'responsive-enabled' class to the table to identify it for JS.
    // This is needed to target tables constructed by this function.
751
    $variables['attributes']['class'][] = 'responsive-enabled';
752
  }
merlinofchaos's avatar
merlinofchaos committed
753 754 755
}

/**
756 757 758 759
 * Prepares variables for views grid style templates.
 *
 * Default template: views-view-grid.html.twig.
 *
760
 * @param array $variables
761 762 763
 *   An associative array containing:
 *   - view: The view object.
 *   - rows: An array of row items. Each row is an array of content.
merlinofchaos's avatar
merlinofchaos committed
764
 */
765
function template_preprocess_views_view_grid(&$variables) {
766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782
  $options = $variables['options'] = $variables['view']->style_plugin->options;
  $horizontal = ($options['alignment'] === 'horizontal');

  $variables['attributes']['class'] = array(
    'views-view-grid',
    $options['alignment'],
    'cols-' . $options['columns'],
    'clearfix',
  );

  $col = 0;
  $row = 0;
  $items = array();
  $remainders = count($variables['rows']) % $options['columns'];
  $num_rows = floor(count($variables['rows']) / $options['columns']);

  // Iterate over each rendered views result row.
783
  foreach ($variables['rows'] as $result_index => $item) {
784 785 786 787 788 789 790 791

    // Add the item.
    if ($horizontal) {
      $items[$row]['content'][$col]['content'] = $item;
    }
    else {
      $items[$col]['content'][$row]['content'] = $item;
    }
merlinofchaos's avatar
merlinofchaos committed
792

793 794 795 796 797 798 799 800 801 802 803 804
    // Create attributes for rows.
    if (!$horizontal || ($horizontal && empty($items[$row]['attributes']))) {
      $row_attributes = array('class' => array());
      // Add default views row classes.
      if ($options['row_class_default']) {
        $row_attributes['class'][] = 'views-row';
        $row_attributes['class'][] = 'row-' . ($row + 1);
        if ($horizontal) {
          $row_attributes['class'][] = 'clearfix';
        }
      }
      // Add custom row classes.
805
      $row_class = array_filter(explode(' ', $variables['view']->style_plugin->getCustomClass($result_index, 'row')));
806 807 808 809 810 811 812 813 814
      if (!empty($row_class)) {
        $row_attributes['class'] = array_merge($row_attributes['class'], $row_class);
      }
      // Add row attributes to the item.
      if ($horizontal) {
        $items[$row]['attributes'] = new Attribute($row_attributes);
      }
      else {
        $items[$col]['content'][$row]['attributes'] = new Attribute($row_attributes);
merlinofchaos's avatar
merlinofchaos committed
815 816
      }
    }
817 818 819 820 821 822 823 824 825 826

    // Create attributes for columns.
    if ($horizontal || (!$horizontal && empty($items[$col]['attributes']))) {
      $col_attributes = array('class' => array());
      // Add default views column classes.
      if ($options['col_class_default']) {
        $col_attributes['class'][] = 'views-col';
        $col_attributes['class'][] = 'col-' . ($col + 1);
        if (!$horizontal) {
          $col_attributes['class'][] = 'clearfix';
merlinofchaos's avatar
merlinofchaos committed
827 828
        }
      }
829
      // Add custom column classes.
830
      $col_class = array_filter(explode(' ', $variables['view']->style_plugin->getCustomClass($result_index, 'col')));
831 832 833 834 835 836 837 838 839 840 841 842 843 844
      if (!empty($col_class)) {
        $col_attributes['class'] = array_merge($col_attributes['class'], $col_class);
      }
      // Add automatic width for columns.
      if ($options['automatic_width']) {
        $col_attributes['style'] = 'width: ' . (100 / $options['columns']) . '%;';
      }
      // Add column attributes to the item.
      if ($horizontal) {
        $items[$row]['content'][$col]['attributes'] = new Attribute($col_attributes);
      }
      else {
        $items[$col]['attributes'] = new Attribute($col_attributes);
      }
merlinofchaos's avatar
merlinofchaos committed
845 846
    }

847 848 849 850 851 852 853 854 855 856 857 858 859 860 861
    // Increase, decrease or reset appropriate integers.
    if ($horizontal) {
      if ($col == 0 && $col != ($options['columns'] - 1)) {
        $col++;
      }
      elseif ($col >= ($options['columns'] - 1)) {
        $col = 0;
        $row++;
      }
      else {
        $col++;
      }
    }
    else {
      $row++;
merlinofchaos's avatar
merlinofchaos committed
862 863 864 865 866 867 868 869 870 871 872 873
      if (!$remainders && $row == $num_rows) {
        $row = 0;
        $col++;
      }
      elseif ($remainders && $row == $num_rows + 1) {
        $row = 0;
        $col++;
        $remainders--;
      }
    }
  }

874 875
  // Add items to the variables array.
  $variables['items'] = $items;
merlinofchaos's avatar
merlinofchaos committed
876 877 878
}

/**
879 880 881 882
 * Prepares variables for views unformatted rows templates.
 *
 * Default template: views-view-unformatted.html.twig.
 *
883
 * @param array $variables
884 885 886
 *   An associative array containing:
 *   - view: The view object.
 *   - rows: An array of row items. Each row is an array of content.
merlinofchaos's avatar
merlinofchaos committed
887
 */
888 889 890
function template_preprocess_views_view_unformatted(&$variables) {
  $view = $variables['view'];
  $rows = $variables['rows'];
merlinofchaos's avatar
merlinofchaos committed
891 892 893 894 895 896 897 898 899
  $style = $view->style_plugin;
  $options = $style->options;

  $default_row_class = isset($options['default_row_class']) ? $options['default_row_class'] : FALSE;
  $row_class_special = isset($options['row_class_special']) ? $options['row_class_special'] : FALSE;
  // Set up striping values.
  $count = 0;
  $max = count($rows);
  foreach ($rows as $id => $row) {
900 901 902
    $variables['rows'][$id] = array();
    $variables['rows'][$id]['content'] = $row;
    $variables['rows'][$id]['attributes'] = array();
merlinofchaos's avatar
merlinofchaos committed
903 904
    $count++;
    if ($default_row_class) {
905 906
      $variables['rows'][$id]['attributes']['class'][] = 'views-row';
      $variables['rows'][$id]['attributes']['class'][] = 'views-row-' . $count;
merlinofchaos's avatar
merlinofchaos committed
907 908
    }
    if ($row_class_special) {
909
      $variables['rows'][$id]['attributes']['class'][] = 'views-row-' . ($count % 2 ? 'odd' : 'even');
merlinofchaos's avatar
merlinofchaos committed
910
      if ($count == 1) {
911
        $variables['rows'][$id]['attributes']['class'][] = 'views-row-first';
merlinofchaos's avatar
merlinofchaos committed
912 913
      }
      if ($count == $max) {
914
        $variables['rows'][$id]['attributes']['class'][] = 'views-row-last';
merlinofchaos's avatar
merlinofchaos committed
915 916
      }
    }
917
    if ($row_class = $view->style_plugin->getRowClass($id)) {
918
      $variables['rows'][$id]['attributes']['class'][] = $row_class;
merlinofchaos's avatar
merlinofchaos committed
919
    }
920
    $variables['rows'][$id]['attributes'] = new Attribute($variables['rows'][$id]['attributes']);
merlinofchaos's avatar
merlinofchaos committed
921 922 923 924
  }
}

/**
925 926 927 928 929 930 931
 * Prepares variables for Views HTML list templates.
 *
 * Default template: views-view-list.html.twig.
 *
 * @param array $variables
 *   An associative array containing:
 *   - view: A View object.
merlinofchaos's avatar
merlinofchaos committed
932
 */
933 934
function template_preprocess_views_view_list(&$variables) {
  $handler  = $variables['view']->style_plugin;
merlinofchaos's avatar
merlinofchaos committed
935

936
  // Fetch classes from handler options.
merlinofchaos's avatar
merlinofchaos committed
937
  $class = explode(' ', $handler->options['class']);
938
  $class = array_map('drupal_clean_css_identifier', $class);
merlinofchaos's avatar
merlinofchaos committed
939

940
  // Fetch wrapper classes from handler options.
merlinofchaos's avatar
merlinofchaos committed
941
  $wrapper_class = explode(' ', $handler->options['wrapper_class']);
942
  $wrapper_class = array_map('drupal_clean_css_identifier', $wrapper_class);
merlinofchaos's avatar
merlinofchaos committed
943

944 945
  // Initialize a new attribute class for $wrapper_class.
  if ($wrapper_class) {
946
    $variables['attributes']['class'] = $wrapper_class;
merlinofchaos's avatar
merlinofchaos committed
947 948
  }

949 950 951
  // Initialize a new attribute class for $class.
  $variables['list']['attributes'] = new Attribute(array('class' => $class));
  $variables['list']['type'] = $handler->options['type'];
952

953
  template_preprocess_views_view_unformatted($variables);
merlinofchaos's avatar
merlinofchaos committed
954 955 956
}

/**
957 958 959 960
 * Prepares variables for RSS feed templates.
 *
 * Default template: views-view-rss.html.twig.
 *
961
 * @param array $variables
962 963 964
 *   An associative array containing:
 *   - view: A ViewExecutable object.
 *   - rows: The raw row data.
965
 */
966
function template_preprocess_views_view_rss(&$variables) {
967
  $view  = $variables['view'];
968
  $items = $variables['rows'];
969
  $style = $view->style_plugin;
merlinofchaos's avatar
merlinofchaos committed
970

971
  $config = \Drupal::config('system.site');
972

merlinofchaos's avatar
merlinofchaos committed
973 974 975
  // The RSS 2.0 "spec" doesn't indicate HTML can be used in the description.
  // We strip all HTML tags, but need to prevent double encoding from properly
  // escaped source data (such as &amp becoming &amp;amp;).
976
  $variables['description'] = check_plain(decode_entities(strip_tags($style->getDescription())));
merlinofchaos's avatar
merlinofchaos committed
977

978
  if ($view->display_handler->getOption('sitename_title')) {
979
    $title = $config->get('name');
980
    if ($slogan = $config->get('slogan')) {
merlinofchaos's avatar
merlinofchaos committed
981 982 983 984
      $title .= ' - ' . $slogan;
    }
  }
  else {
985
    $title = $view->getTitle();
merlinofchaos's avatar
merlinofchaos committed
986
  }
987
  $variables['title'] = check_plain($title);
merlinofchaos's avatar
merlinofchaos committed
988

989 990
  // Figure out which display which has a path we're using for this feed. If
  // there isn't one, use the global $base_url
991
  $link_display_id = $view->display_handler->getLinkDisplay();
992 993
  if ($link_display_id && $display = $view->displayHandlers->get($link_display_id)) {
    $path = $view->displayHandlers->get($link_display_id)->getPath();
merlinofchaos's avatar
merlinofchaos committed
994 995 996
  }

  if ($path) {
997
    $path = $view->getUrl(NULL, $path);
merlinofchaos's avatar
merlinofchaos committed
998 999 1000 1001 1002
    $url_options = array('absolute' => TRUE);
    if (!empty($view->exposed_raw_input)) {
      $url_options['query'] = $view->exposed_raw_input;
    }

1003 1004
    // Compare the link to the default home page; if it's the default home page,
    // just use $base_url.
1005
    if ($path == $config->get('page.front')) {
merlinofchaos's avatar
merlinofchaos committed
1006 1007 1008
      $path = '';
    }

1009
    $variables['link'] = check_url(url($path, $url_options));
merlinofchaos's avatar
merlinofchaos committed
1010 1011
  }

1012 1013 1014 1015
  $variables['langcode'] = check_plain(language(Language::TYPE_INTERFACE)->id);
  $variables['namespaces'] = new Attribute($style->namespaces);
  $variables['items'] = $items;
  $variables['channel_elements'] = format_xml_elements($style->channel_elements);
merlinofchaos's avatar
merlinofchaos committed
1016 1017 1018

  // During live preview we don't want to output the header since the contents
  // of the feed are being displayed inside a normal HTML page.
1019 1020
  if (empty($variables['view']->live_preview)) {
    $variables['view']->getResponse()->headers->set('Content-Type', 'application/rss+xml; charset=utf-8');
merlinofchaos's avatar
merlinofchaos committed
1021 1022 1023 1024
  }
}

/**
1025 1026 1027 1028
 * Prepares variables for views RSS item templates.
 *
 * Default template: views-view-row-rss.html.twig.
 *
1029
 * @param array $variables
1030 1031
 *   An associative array containing:
 *   - row: The raw results rows.
merlinofchaos's avatar
merlinofchaos committed
1032
 */
1033 1034
function template_preprocess_views_view_row_rss(&$variables) {
  $item = $variables['row'];
merlinofchaos's avatar
merlinofchaos committed
1035

1036 1037 1038 1039
  $variables['title'] = check_plain($item->title);
  $variables['link'] = check_url($item->link);
  $variables['description'] = check_plain($item->description);
  $variables['item_elements'] = empty($item->elements) ? '' : format_xml_elements($item->elements);