You are here

public function SlickFormatter::getThumbnail in Slick Carousel 7.3

Same name and namespace in other branches
  1. 8.2 src/SlickFormatter.php \Drupal\slick\SlickFormatter::getThumbnail()
  2. 8 src/SlickFormatter.php \Drupal\slick\SlickFormatter::getThumbnail()

Gets the thumbnail image using theme_image_style().

Parameters

array $settings: The array containing: thumbnail_style, etc.

object $item: The \Drupal\image\Plugin\Field\FieldType\ImageItem object.

Return value

array The renderable array of thumbnail image.

Overrides SlickFormatterInterface::getThumbnail

File

src/SlickFormatter.php, line 69

Class

SlickFormatter
Implements SlickFormatterInterface.

Namespace

Drupal\slick

Code

public function getThumbnail(array $settings = [], $item = NULL) {
  $thumbnail = [];
  $uri = empty($settings['thumbnail_uri']) ? $settings['uri'] : $settings['thumbnail_uri'];
  if (!empty($uri)) {
    $thumbnail = [
      '#theme' => 'image_style',
      '#style_name' => $settings['thumbnail_style'] ?: 'thumbnail',
      '#path' => $uri,
    ];

    // Extract relevant variables from image or file entity/ media.
    if ($item) {
      foreach ([
        'attributes',
        'height',
        'weight',
        'alt',
        'title',
      ] as $key) {

        // Do not output empty value to prevent ugly title undefined.
        if (isset($item->{$key})) {
          $thumbnail["#{$key}"] = $item->{$key};
        }
      }
    }
  }
  return $thumbnail;
}