You are here

protected function MediaThumbnailFormatter::getMediaThumbnailUrl in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/media/src/Plugin/Field/FieldFormatter/MediaThumbnailFormatter.php \Drupal\media\Plugin\Field\FieldFormatter\MediaThumbnailFormatter::getMediaThumbnailUrl()
  2. 9 core/modules/media/src/Plugin/Field/FieldFormatter/MediaThumbnailFormatter.php \Drupal\media\Plugin\Field\FieldFormatter\MediaThumbnailFormatter::getMediaThumbnailUrl()

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 MediaThumbnailFormatter::getMediaThumbnailUrl()
MediaThumbnailFormatter::viewElements in core/modules/media/src/Plugin/Field/FieldFormatter/MediaThumbnailFormatter.php
Builds a renderable array for a field value.

File

core/modules/media/src/Plugin/Field/FieldFormatter/MediaThumbnailFormatter.php, line 189

Class

MediaThumbnailFormatter
Plugin implementation of the 'media_thumbnail' formatter.

Namespace

Drupal\media\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;
}