You are here

public function BrightcoveVideoEntityController::create in Brightcove Video Connect 7.7

Same name and namespace in other branches
  1. 7.6 brightcove.video.inc \BrightcoveVideoEntityController::create()

Implements EntityAPIControllerInterface.

Overrides EntityAPIController::create

File

./brightcove.video.inc, line 20
Brightcove video related functions.

Class

BrightcoveVideoEntityController
Entity controller class for Brightcove video.

Code

public function create(array $values = []) {
  brightcove_load_lib();

  // Add is_new property if it is not set.
  $values += [
    'is_new' => TRUE,
  ];
  if (empty($values['client']) || !$values['client'] instanceof Entity) {
    throw new Exception(t('Cannot create a brightcove_video entity without a client.'));
  }
  if (empty($values['video_id'])) {
    $values['video'] = new \Brightcove\Object\Video\Video();
    $values['video_id'] = NULL;
  }
  elseif ($video = brightcove_load_video($values['video_id'], $values['client'])) {
    $values['video'] = $video;
    $values['account_id'] = $values['client']->account_id;
    $values['label'] = $video
      ->getName();
  }
  else {
    throw new Exception(t('Failure to load the video @video with client @client', [
      '@video' => $values['video_id'],
      '@client' => $values['client']->bcid,
    ]));
  }

  // Add a Video object to the entity object.
  brightcove_load_lib();
  $video_entity = new Entity($values, $this->entityType);
  return $video_entity;
}