function template_preprocess_views_view_summary_unformatted

Prepares variables for unformatted summary view templates.

Default template: views-view-summary-unformatted.html.twig.

Parameters

array $vars: 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.

File

drupal/core/modules/views/views.theme.inc, line 472
Preprocessors and helper functions to make theming easier.

Code

function template_preprocess_views_view_summary_unformatted(&$vars) {
  $view = $vars['view'];
  $argument = $view->argument[$view->build_info['summary_level']];
  $vars['row_classes'] = array();
  $url_options = array();
  if (!empty($view->exposed_raw_input)) {
    $url_options['query'] = $view->exposed_raw_input;
  }
  $count = 0;
  $active_urls = drupal_map_assoc(array(
    // Force system path.
    url(current_path(), array(
      'alias' => TRUE,
    )),
    // Could be an alias.
    url(current_path()),
  ));

  // 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.
  $row_args = array();
  foreach ($vars['rows'] as $id => $row) {
    $row_args[$id] = $argument
      ->summaryArgument($row);
  }
  $argument
    ->processSummaryArguments($row_args);
  foreach ($vars['rows'] as $id => $row) {

    // Only false on first time.
    if ($count++) {
      $vars['rows'][$id]->separator = filter_xss_admin($vars['options']['separator']);
    }
    $vars['rows'][$id]->link = $argument
      ->summaryName($row);
    $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'];
    }
    $vars['rows'][$id]->url = url($view
      ->getUrl($args, $base_path), $url_options);
    $vars['rows'][$id]->count = intval($row->{$argument->count_alias});
    $vars['row_classes'][$id] = array();
    if (isset($active_urls[$vars['rows'][$id]->url])) {
      $vars['row_classes'][$id]['class'][] = 'active';
    }
    $vars['row_classes'][$id] = new Attribute($vars['row_classes'][$id]);
  }
}