You are here

public function BrightcoveVideoEntityController::load in Brightcove Video Connect 7.6

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

Overridden.

In contrast to the parent implementation we factor out query execution, so fetching can be further customized easily.

Overrides EntityAPIController::load

See also

DrupalDefaultEntityController#load($ids, $conditions)

File

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

Class

BrightcoveVideoEntityController
Entity controller class for Brightcove video.

Code

public function load($ids = [], $conditions = []) {
  $entities = parent::load($ids, $conditions);

  // Add the Video object to each entity object.
  foreach ($entities as $key => $entity) {
    if (empty($entity->video) || !$entity->video instanceof \Brightcove\Object\Video\Video) {
      if (empty($entity->client) || !$entity->client instanceof Entity) {
        $clients = brightcove_get_clients_by_account_id($entity->account_id);
        $found_client = FALSE;
        foreach ($clients as $client) {
          if ($video = brightcove_load_video($entity->video_id, $client)) {
            $entity->video = $video;
            $entity->client = $client;
            $found_client = TRUE;
            break;
          }
        }
        if (!$found_client) {
          $video_id = $entity->video_id;
          unset($entities[$key]);
          watchdog('brightcove', 'Could not load the video @video_id.', [
            '@video_id' => $video_id,
          ], WATCHDOG_WARNING);
        }
      }
      else {
        $entity->video = brightcove_load_video($entity->video_id, $entity->client);
      }
    }
    $entity->label = $entity->video
      ->getName();
  }
  return $entities;
}