You are here

protected function ProviderPluginBase::downloadThumbnail in Video 8

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

Download the remote thumbnail to the local file system.

1 call to ProviderPluginBase::downloadThumbnail()
ProviderPluginBase::renderThumbnail in src/ProviderPluginBase.php

File

src/ProviderPluginBase.php, line 120

Class

ProviderPluginBase
A base for the provider plugins.

Namespace

Drupal\video

Code

protected function downloadThumbnail() {
  $local_uri = $this
    ->getLocalThumbnailUri();
  if (!file_exists($local_uri)) {
    $thumb_dir = $this
      ->getUploadLocation();
    file_prepare_directory($thumb_dir, FILE_CREATE_DIRECTORY);
    $remote_url = $this
      ->getRemoteThumbnailUrl();
    if ($remote_url) {
      $thumbnail = $this->httpClient
        ->request('GET', $this
        ->getRemoteThumbnailUrl());
      file_unmanaged_save_data((string) $thumbnail
        ->getBody(), $local_uri);
    }
  }
}