You are here

function template_preprocess_uikit_view_list in UIkit Components 8.3

Same name and namespace in other branches
  1. 8 uikit_views/includes/uikit_views.theme.inc \template_preprocess_uikit_view_list()
  2. 8.2 uikit_views/includes/uikit_views.theme.inc \template_preprocess_uikit_view_list()
  3. 7.3 uikit_views/templates/uikit_views.theme.inc \template_preprocess_uikit_view_list()
  4. 7.2 uikit_views/templates/uikit_views.theme.inc \template_preprocess_uikit_view_list()

Prepares variables for UIkit List templates.

Default template: uikit-view-list.html.twig.

Parameters

array $variables: An associative array containing:

  • view: A ViewExecutable object.
  • rows: The raw row data.
1 string reference to 'template_preprocess_uikit_view_list'
UIkitViews::getThemeHooks in uikit_views/src/UIkitViews.php
Returns the theme hook definition information for UIkit Views.

File

uikit_views/includes/uikit_views.theme.inc, line 137
Preprocessors and helper functions to make theming easier.

Code

function template_preprocess_uikit_view_list(array &$variables) {
  $view = $variables['view'];
  $options = $view->style_plugin->options;

  // Set the wrapper attributes.
  $variables['attributes'] = new Attribute();
  if ($options['wrapper_class']) {
    $variables['attributes']
      ->addClass($options['wrapper_class']);
  }

  // Set the list attributes.
  $variables['list_attributes'] = new Attribute();
  $variables['list_attributes']['class'] = [
    'uk-list',
  ];
  if ($options['class'] != 'default') {
    $variables['list_attributes']['class'][] = $options['class'];
  }
  $items = [];

  // Iterate over each rendered views result row.
  foreach ($variables['rows'] as $result_index => $item) {
    $items[$result_index]['content'] = $item;
  }

  // Add items to the variables array.
  $variables['items'] = $items;
}