You are here

protected function MediaElementVideoFieldFormatter::getPosterPath in MediaElement 8

Returns the file path for the video's `poster` attribute, if set.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The current entity being rendered.

Return value

string The path to the poster image.

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

File

src/Plugin/Field/FieldFormatter/MediaElementVideoFieldFormatter.php, line 178

Class

MediaElementVideoFieldFormatter
Plugin implementation of the 'mediaelement_file_video' formatter.

Namespace

Drupal\mediaelement\Plugin\Field\FieldFormatter

Code

protected function getPosterPath(EntityInterface $entity) {
  $image_field = $this->settings['poster_image_field'];
  $image_style = $this->settings['poster_image_style'];

  // @codingStandardsIgnoreLine
  if ($image_field == 'none') {
    return '';
  }
  if ($entity
    ->get($image_field)
    ->isEmpty()) {
    return '';
  }
  $image_uri = $entity->{$image_field}->entity
    ->getFileUri();
  $image_url = $image_style == 'raw' ? file_create_url($image_uri) : $this->imageStyleStorage
    ->load($image_style)
    ->buildUrl($image_uri);
  return file_url_transform_relative($image_url);
}