You are here

function template_preprocess_uikit_view_accordion in UIkit Components 8.3

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

Prepares variables for UIkit Accordion templates.

Default template: uikit-view-accordion.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_accordion'
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 21
Preprocessors and helper functions to make theming easier.

Code

function template_preprocess_uikit_view_accordion(array &$variables) {
  $view = $variables['view'];
  $options = $view->style_plugin->options;
  $title_field = $options['title_field'];
  $accordion_data = [];
  $items = [];
  if ($title_field) {
    foreach ($variables['rows'] as $result_index => $item) {
      $title = $view->style_plugin
        ->getFieldValue($result_index, $title_field);
      $items[$result_index]['content'] = $item;
      $items[$result_index]['title'] = $title;
    }
  }

  // Set items array for twig template.
  $variables['items'] = $items;

  // Create attributes for accordion.
  $accordion_data[] = 'targets: ' . ($options['targets'] ? $options['targets'] : '> *');
  $accordion_data[] = 'active: ' . ($options['active'] ? $options['active'] : 'false');
  $accordion_data[] = 'collapsible: ' . ($options['collapsible'] ? 'true' : 'false');
  $accordion_data[] = 'multiple: ' . ($options['multiple'] ? 'true' : 'false');
  $accordion_data[] = 'animation: ' . ($options['animation'] ? 'true' : 'false');
  $accordion_data[] = 'transition: ' . $options['transition'];
  $accordion_data[] = 'duration: ' . $options['duration'];
  $data_accordion = implode('; ', $accordion_data);
  $accordion_attributes = new Attribute();
  $accordion_attributes
    ->addClass('uk-accordion');
  $accordion_attributes
    ->setAttribute('data-uk-accordion', $data_accordion);

  // Set accordion attributes for twig template.
  $variables['accordion_attributes'] = $accordion_attributes;
}