You are here

function template_preprocess_flexslider_list_item in Flex Slider 8.2

Prepares variables for flexslider list item template.

Default template: flexslider-list-item.html.twig.

File

templates/flexslider.theme.inc, line 140
Theming functions for the flexslider module.

Code

function template_preprocess_flexslider_list_item(&$variables) {

  // Reference configuration variables.
  $item =& $variables['item'];
  $settings =& $variables['settings'];
  $caption =& $variables['caption'];
  $attributes =& $variables['attributes'];

  /** @var \Drupal\flexslider\Entity\Flexslider $optionset */
  $optionset = $settings['optionset'];

  // Generated thumbnail support.
  if ($optionset
    ->getOption('controlNav') === "thumbnails") {

    // If the thumbnails are enabled in the option set,
    // extract the url to set as the thumbnail data.
    $src = [];
    if (!preg_match("/<img.+?src=[\"'](.+?)[\"'].+?>/", $item, $src)) {
      preg_match("/<img.+?srcset=[\"'](.+?)[\"'].+?>/", $item, $src);
    }
    if (!empty($src[1])) {
      $attributes['data-thumb'] = $src[1];
    }

    // Let's also get the alt attribute to apply to thumbnails.
    // This only works in library version 2.6+.
    $alt = [];
    preg_match("/<img.+?alt=[\"'](.*?)[\"'].+?>/", $item, $alt);
    if (!empty($alt)) {
      $attributes['data-thumb-alt'] = $alt[1];
    }
  }
  if ($optionset
    ->getOption('thumbCaptions') and !empty($caption)) {
    $attributes['data-thumbcaption'] = $caption;

    // Prevent captions from appearing in the slider as well.
    if (FALSE === $optionset
      ->getOption('thumbCaptionsBoth')) {
      $caption = '';
    }
  }
}