You are here

protected function BrightcoveVideo::createIngestImage in Brightcove Video Connect 8.2

Same name and namespace in other branches
  1. 8 src/Entity/BrightcoveVideo.php \Drupal\brightcove\Entity\BrightcoveVideo::createIngestImage()
  2. 3.x src/Entity/BrightcoveVideo.php \Drupal\brightcove\Entity\BrightcoveVideo::createIngestImage()

Create an ingestion request for image.

Parameters

string $type: The type of the image, possible values are:

  • IMAGE_TYPE_POSTER
  • IMAGE_TYPE_THUMBNAIL

.

Throws

\Exception If the $type is not matched with the possible types.

1 call to BrightcoveVideo::createIngestImage()
BrightcoveVideo::save in src/Entity/BrightcoveVideo.php

File

src/Entity/BrightcoveVideo.php, line 235

Class

BrightcoveVideo
Defines the Brightcove Video entity.

Namespace

Drupal\brightcove\Entity

Code

protected function createIngestImage($type) {
  if (!in_array($type, [
    self::IMAGE_TYPE_POSTER,
    self::IMAGE_TYPE_THUMBNAIL,
  ])) {
    throw new \Exception(t("Invalid type given: @type, the type argument must be either '@thumbnail' or '@poster'.", [
      '@type' => $type,
      '@thumbnail' => self::IMAGE_TYPE_THUMBNAIL,
      '@poster' => self::IMAGE_TYPE_POSTER,
    ]));
  }
  $function = ucfirst($type);

  // Set up image ingestion.
  if (!empty($this
    ->{"get{$function}"}()['target_id'])) {
    $ingest_request = $this
      ->getIngestRequest();

    /** @var \Drupal\file\Entity\File $file */
    $file = File::load($this
      ->{"get{$function}"}()['target_id']);

    // Load the image object factory so we can access height and width.
    $image_factory = \Drupal::service('image.factory');
    $image = $image_factory
      ->get($file
      ->getFileUri());
    if (!is_null($image)) {
      $ingest_image = new IngestImage();
      $ingest_image
        ->setUrl(file_create_url($file
        ->getFileUri()));
      $ingest_image
        ->setWidth($image
        ->getWidth());
      $ingest_image
        ->setHeight($image
        ->getHeight());
      $ingest_request
        ->{"set{$function}"}($ingest_image);
    }
  }
}