function template_preprocess_views_view_summary_unformatted in Zircon Profile 8.0
Same name and namespace in other branches
- 8 core/modules/views/views.theme.inc \template_preprocess_views_view_summary_unformatted()
Prepares variables for unformatted summary view templates.
Default template: views-view-summary-unformatted.html.twig.
Parameters
array $variables: 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
- core/
modules/ views/ views.theme.inc, line 309 - Preprocessors and helper functions to make theming easier.
Code
function template_preprocess_views_view_summary_unformatted(&$variables) {
$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;
}
$count = 0;
$active_urls = array(
// Force system path.
\Drupal::url('<current>', [], [
'alias' => TRUE,
]),
// Could be an alias.
\Drupal::url('<current>'),
);
$active_urls = array_combine($active_urls, $active_urls);
// 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 ($variables['rows'] as $id => $row) {
$row_args[$id] = $argument
->summaryArgument($row);
}
$argument
->processSummaryArguments($row_args);
foreach ($variables['rows'] as $id => $row) {
// Only false on first time.
if ($count++) {
$variables['rows'][$id]->separator = Xss::filterAdmin($variables['options']['separator']);
}
$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]->active = isset($active_urls[$variables['rows'][$id]->url]);
$variables['rows'][$id]->attributes = new Attribute($variables['rows'][$id]->attributes);
}
}