function MediaThumbnailFormatter::getMediaThumbnailUrl

Same name in other branches
  1. 9 core/modules/media/src/Plugin/Field/FieldFormatter/MediaThumbnailFormatter.php \Drupal\media\Plugin\Field\FieldFormatter\MediaThumbnailFormatter::getMediaThumbnailUrl()
  2. 8.9.x core/modules/media/src/Plugin/Field/FieldFormatter/MediaThumbnailFormatter.php \Drupal\media\Plugin\Field\FieldFormatter\MediaThumbnailFormatter::getMediaThumbnailUrl()
  3. 11.x 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 197

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;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.