You are here

protected function MediaResponsiveThumbnailFormatter::getMediaThumbnailUrl in Media Responsive Thumbnail 8

Get the URL for the media thumbnail.

Parameters

\Drupal\media\MediaInterface $media: The media item.

\Drupal\Core\Entity\EntityInterface $entity: The entity that the field belongs to.

Return value

\Drupal\Core\Url|null The URL object for the media item or null if we don't want to add a link.

1 call to MediaResponsiveThumbnailFormatter::getMediaThumbnailUrl()
MediaResponsiveThumbnailFormatter::viewElements in src/Plugin/Field/FieldFormatter/MediaResponsiveThumbnailFormatter.php
Builds a renderable array for a field value.

File

src/Plugin/Field/FieldFormatter/MediaResponsiveThumbnailFormatter.php, line 206

Class

MediaResponsiveThumbnailFormatter
Plugin implementation of the 'media_responsive_thumbnail' formatter.

Namespace

Drupal\media_responsive_thumbnail\Plugin\Field\FieldFormatter

Code

protected function getMediaThumbnailUrl(MediaInterface $media, EntityInterface $entity) {
  $url = NULL;
  $image_link_setting = $this
    ->getSetting('image_link');

  // Check if the formatter involves a link.
  if ($image_link_setting == 'content') {
    if (!$entity
      ->isNew()) {
      $url = $entity
        ->toUrl();
    }
  }
  elseif ($image_link_setting === 'media') {
    $url = $media
      ->toUrl();
  }
  return $url;
}