You are here

function template_preprocess_uikit_view_accordion in UIkit Components 7.3

Same name and namespace in other branches
  1. 8.3 uikit_views/includes/uikit_views.theme.inc \template_preprocess_uikit_view_accordion()
  2. 8.2 uikit_views/includes/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.tpl.php.

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'
uikit_views_theme in uikit_views/uikit_views.module
Implements hook_theme().

File

uikit_views/templates/uikit_views.theme.inc, line 18
Preprocessors and helper functions to make theming easier.

Code

function template_preprocess_uikit_view_accordion(&$variables) {
  $view = $variables['view'];
  $handler = $view->style_plugin;
  $options = $handler->options;
  $title_field = $options['title_field'];
  $accordion_data = [];
  $items = [];
  if ($title_field) {
    foreach ($variables['rows'] as $result_index => $item) {
      $title_value = $handler
        ->get_field($result_index, $title_field);
      $title = preg_replace('/<a[^>]*?>([\\s\\S]*?)<\\/a>/', '\\1', $title_value);
      $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['class'][] = 'uk-accordion';
  $accordion_attributes['uk-accordion'] = $data_accordion;

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