You are here

private function BrightcoveVideo::deleteFile in Brightcove Video Connect 8

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

Helper function to delete a file from the entity.

Parameters

int $target_id: The target ID of the saved file.

Return value

\Drupal\brightcove\BrightcoveVideoInterface The called Brightcove Video.

Throws

\Exception If the $target_id is not a positive number or zero.

3 calls to BrightcoveVideo::deleteFile()
BrightcoveVideo::setPoster in src/Entity/BrightcoveVideo.php
Sets the video's poster image.
BrightcoveVideo::setThumbnail in src/Entity/BrightcoveVideo.php
Sets the video's thumbnail image.
BrightcoveVideo::setVideoFile in src/Entity/BrightcoveVideo.php
Sets the video file.

File

src/Entity/BrightcoveVideo.php, line 199

Class

BrightcoveVideo
Defines the Brightcove Video entity.

Namespace

Drupal\brightcove\Entity

Code

private function deleteFile($target_id) {
  if (!is_numeric($target_id) || $target_id <= 0) {
    throw new \Exception(t('Target ID must be non-zero number.'));
  }

  /** @var \Drupal\file\Entity\File $file */
  $file = File::load($target_id);

  // Delete image.
  // @TODO: Check for multiple file references when it will be needed.
  // So far as I find it, it is not possible to create multiple file
  // references on the Drupal's UI, so it should be OK now.
  if (!is_null($file)) {
    $file
      ->delete();
  }
  return $this;
}