You are here

function template_preprocess_views_slideshow_pager_fields in Views Slideshow 8.3

Same name and namespace in other branches
  1. 8.4 views_slideshow.theme.inc \template_preprocess_views_slideshow_pager_fields()
  2. 6.3 views_slideshow.module \template_preprocess_views_slideshow_pager_fields()
  3. 7.3 theme/views_slideshow.theme.inc \template_preprocess_views_slideshow_pager_fields()

Theme pager fields.

File

./views_slideshow.theme.inc, line 212
The theme system, which controls the output of views slideshow.

Code

function template_preprocess_views_slideshow_pager_fields(&$vars) {

  // Add javascript settings for the field.
  $vars['#attached']['library'][] = 'views_slideshow/widget_info';
  $vars['#attached']['drupalSettings']['viewsSlideshowPagerFields'][$vars['vss_id']] = array(
    $vars['location'] => array(
      'activatePauseOnHover' => $vars['settings']['views_slideshow_pager_fields_hover'],
    ),
  );

  // Add hover intent library.
  // @todo Check if there is a better way to detect optional libraries.
  if ($vars['settings']['views_slideshow_pager_fields_hover']) {
    $hoverIntent = \Drupal::service('library.discovery')
      ->getLibraryByName('views_slideshow', 'jquery_hoverIntent');
    if (isset($hoverIntent['js'][0]['data']) && file_exists($hoverIntent['js'][0]['data'])) {
      $vars['#attached']['library'][] = 'views_slideshow/jquery_hoverIntent';
    }
  }
  $vars['widget_id'] = $vars['attributes']['id'];

  // Add our class to the wrapper.
  $vars['attributes']['class'][] = 'views_slideshow_pager_field';

  // Render all the fields unless there is only 1 slide and the user specified
  // to hide them when there is only one slide.
  $vars['rendered_field_items'] = '';
  if (empty($vars['settings']['hide_on_single_slide']) || count($vars['view']->result) > $vars['view']->style_options['views_slideshow_cycle']['items_per_slide']) {
    foreach ($vars['view']->result as $count => $node) {
      $rendered_fields = '';
      foreach ($vars['settings']['views_slideshow_pager_fields_fields'] as $field => $use) {
        if ($use !== 0 && is_object($vars['view']->field[$field])) {
          $rendered_fields[] = array(
            '#theme' => $vars['view']
              ->buildThemeFunctions('views_slideshow_pager_field_field'),
            '#view' => $vars['view'],
            '#label' => $vars['view']->field[$field]->options['label'],
            '#output' => $vars['view']->style_plugin
              ->getField($count, $field),
            '#css_identifier' => Html::cleanCssIdentifier($vars['view']->field[$field]->field),
          );
        }
      }
      $vars['rendered_field_items'][] = array(
        '#theme' => $vars['view']
          ->buildThemeFunctions('views_slideshow_pager_field_item'),
        '#vss_id' => $vars['vss_id'],
        '#item' => $rendered_fields,
        '#count' => $count,
        '#location' => $vars['location'],
        '#length' => count($vars['view']->result),
      );
    }
  }
}