You are here

public function Slideshow::thumbnail in Media entity slideshow 8

Gets thumbnail image.

Media type plugin is responsible for returning URI of the generic thumbnail if no other is available. This functions should always return a valid URI.

Parameters

MediaInterface $media: Media.

Return value

string URI of the thumbnail.

Overrides MediaTypeInterface::thumbnail

File

src/Plugin/MediaEntity/Type/Slideshow.php, line 95

Class

Slideshow
Provides media type plugin for Slideshows.

Namespace

Drupal\media_entity_slideshow\Plugin\MediaEntity\Type

Code

public function thumbnail(MediaInterface $media) {
  $source_field = $this->configuration['source_field'];

  /** @var \Drupal\media_entity\MediaInterface $slideshow_item */
  $slideshow_item = $this->entityTypeManager
    ->getStorage('media')
    ->load($media->{$source_field}->target_id);
  if (!$slideshow_item) {
    return $this
      ->getDefaultThumbnail();
  }

  /** @var \Drupal\media_entity\MediaBundleInterface $bundle */
  $bundle = $this->entityTypeManager
    ->getStorage('media_bundle')
    ->load($slideshow_item
    ->bundle());
  if (!$bundle) {
    return $this
      ->getDefaultThumbnail();
  }
  $thumbnail = $bundle
    ->getType()
    ->thumbnail($slideshow_item);
  if (!$thumbnail) {
    return $this
      ->getDefaultThumbnail();
  }
  return $thumbnail;
}