You are here

function template_preprocess_image_jssor_formatter in Jssor Slider 8

Prepares variables for image jssor formatter templates.

Default template: image-jssor-formatter.html.twig.

Parameters

array $variables: An associative array containing:

  • item: An ImageItem object.
  • item_attributes: An optional associative array of html attributes to be placed in the img tag.
  • image_style: An optional image style.
  • url: An optional \Drupal\Core\Url object.

File

./jssor.theme.inc, line 220
Preprocessors and helper functions to make theming easier.

Code

function template_preprocess_image_jssor_formatter(&$variables) {
  if ($variables['image_style']) {
    $variables['image'] = array(
      '#theme' => 'image_style',
      '#style_name' => $variables['image_style'],
    );
  }
  else {
    $variables['image'] = array(
      '#theme' => 'image',
    );
  }
  $variables['image']['#attributes'] = $variables['item_attributes'];
  $item = $variables['item'];

  // Do not output an empty 'title' attribute.
  if (Unicode::strlen($item->title) != 0) {
    $variables['image']['#title'] = $item->title;
  }
  if (($entity = $item->entity) && empty($item->uri)) {
    $variables['image']['#uri'] = $entity
      ->getFileUri();
  }
  else {
    $variables['image']['#uri'] = $item->uri;
  }
  foreach (array(
    'width',
    'height',
    'alt',
  ) as $key) {
    $variables['image']["#{$key}"] = $item->{$key};
  }
  $variables['caption_text'] = $item->alt;
}