You are here

public function ProviderPluginBase::downloadThumbnail in Video Embed Field 8.2

Same name and namespace in other branches
  1. 8 src/ProviderPluginBase.php \Drupal\video_embed_field\ProviderPluginBase::downloadThumbnail()

Download the remote thumbnail URL to the local thumbnail URI.

Overrides ProviderPluginInterface::downloadThumbnail

File

src/ProviderPluginBase.php, line 141

Class

ProviderPluginBase
A base for the provider plugins.

Namespace

Drupal\video_embed_field

Code

public function downloadThumbnail() {
  $local_uri = $this
    ->getLocalThumbnailUri();
  if (!file_exists($local_uri)) {
    $this
      ->getFileSystem()
      ->prepareDirectory($this->thumbsDirectory, FileSystemInterface::CREATE_DIRECTORY);
    try {
      $thumbnail = $this->httpClient
        ->request('GET', $this
        ->getRemoteThumbnailUrl());
      $this
        ->getFileSystem()
        ->saveData((string) $thumbnail
        ->getBody(), $local_uri);
    } catch (\Exception $e) {
    }
  }
}