You are here

protected function Media::updateThumbnail in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/media/src/Entity/Media.php \Drupal\media\Entity\Media::updateThumbnail()

Update the thumbnail for the media item.

@internal

@todo There has been some disagreement about how to handle updates to thumbnails. We need to decide on what the API will be for this. https://www.drupal.org/node/2878119

Parameters

bool $from_queue: Specifies whether the thumbnail update is triggered from the queue.

Return value

\Drupal\media\MediaInterface The updated media item.

1 call to Media::updateThumbnail()
Media::updateQueuedThumbnail in core/modules/media/src/Entity/Media.php
Updates the queued thumbnail for the media item.

File

core/modules/media/src/Entity/Media.php, line 155

Class

Media
Defines the media entity class.

Namespace

Drupal\media\Entity

Code

protected function updateThumbnail($from_queue = FALSE) {
  $this->thumbnail->target_id = $this
    ->loadThumbnail($this
    ->getThumbnailUri($from_queue))
    ->id();

  // Set the thumbnail alt.
  $media_source = $this
    ->getSource();
  $plugin_definition = $media_source
    ->getPluginDefinition();
  $this->thumbnail->alt = '';
  if (!empty($plugin_definition['thumbnail_alt_metadata_attribute'])) {
    $this->thumbnail->alt = $media_source
      ->getMetadata($this, $plugin_definition['thumbnail_alt_metadata_attribute']);
  }
  return $this;
}