You are here

function template_preprocess_uikit_view_accordion in UIkit Components 7.2

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.3 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 20
Preprocessors and helper functions to make theming easier.

Code

function template_preprocess_uikit_view_accordion(&$variables) {
  UIkitComponents::getUIkitAsset('accordion');
  $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[] = 'showfirst: ' . ($options['showfirst'] ? 'true' : 'false');
  $accordion_data[] = 'collapse: ' . ($options['collapse'] ? 'true' : 'false');
  $accordion_data[] = 'animate: ' . ($options['animate'] ? 'true' : 'false');
  $accordion_data[] = "easing: '" . $options['easing'] . "'";
  $accordion_data[] = 'duration: ' . $options['duration'];
  $accordion_data[] = "toggle: '" . $options['toggle'] . "'";
  $accordion_data[] = "containers: '" . $options['containers'] . "'";
  $accordion_data[] = "clsactive: '" . $options['clsactive'] . "'";
  $data_accordion = '{' . implode(', ', $accordion_data) . '}';
  $accordion_attributes['class'][] = 'uk-accordion';
  $accordion_attributes['data-uk-accordion'] = $data_accordion;

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

  // Set the accordion toggle and container elements.
  $selectors = '/[.#\\[\\]]/i';
  $variables['accordion_toggle'] = preg_replace($selectors, '', $options['toggle']);
  $variables['accordion_container'] = preg_replace($selectors, '', $options['containers']);
}