function Media::updateThumbnail

Same name in other branches
  1. 9 core/modules/media/src/Entity/Media.php \Drupal\media\Entity\Media::updateThumbnail()
  2. 8.9.x core/modules/media/src/Entity/Media.php \Drupal\media\Entity\Media::updateThumbnail()
  3. 11.x 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 161

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();
    $this->thumbnail->width = $this->getThumbnailWidth($from_queue);
    $this->thumbnail->height = $this->getThumbnailHeight($from_queue);
    // 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;
}

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