You are here

function template_preprocess_views_view_summary in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/views/views.theme.inc \template_preprocess_views_view_summary()

Prepares variables for views summary templates.

The summary prints a single record from a row, with fields.

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

Parameters

array $variables: An associative array containing:

  • view: A ViewExecutable object.
  • rows: The raw row data.

File

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

Code

function template_preprocess_views_view_summary(&$variables) {

  /** @var \Drupal\views\ViewExecutable $view */
  $view = $variables['view'];
  $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 = array(
    // Force system path.
    \Drupal::url('<current>', [], [
      'alias' => TRUE,
    ]),
    // Force system path.
    Url::fromRouteMatch(\Drupal::routeMatch())
      ->setOption('alias', TRUE)
      ->toString(),
    // Could be an alias.
    \Drupal::url('<current>'),
    // Could be an alias.
    Url::fromRouteMatch(\Drupal::routeMatch())
      ->toString(),
  );
  $active_urls = array_combine($active_urls, $active_urls);

  // 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.
  $row_args = array();
  foreach ($variables['rows'] as $id => $row) {
    $row_args[$id] = $argument
      ->summaryArgument($row);
  }
  $argument
    ->processSummaryArguments($row_args);
  foreach ($variables['rows'] as $id => $row) {
    $variables['rows'][$id]->attributes = array();
    $variables['rows'][$id]->link = $argument
      ->summaryName($row);
    $args = $view->args;
    $args[$argument->position] = $row_args[$id];
    if (!empty($argument->options['summary_options']['base_path'])) {
      $base_path = $argument->options['summary_options']['base_path'];
      $tokens = $this
        ->getArgumentsTokens();
      $base_path = $this
        ->viewsTokenReplace($base_path, $tokens);

      // @todo Views should expect and store a leading /. See:
      //   https://www.drupal.org/node/2423913
      $url = Url::fromUserInput('/' . $base_path);
    }
    else {
      $url = $view
        ->getUrl($args)
        ->setOptions($url_options);
    }
    $variables['rows'][$id]->url = $url
      ->toString();
    $variables['rows'][$id]->count = intval($row->{$argument->count_alias});
    $variables['rows'][$id]->attributes = new Attribute($variables['rows'][$id]->attributes);
    $variables['rows'][$id]->active = isset($active_urls[$variables['rows'][$id]->url]);
  }
}