protected static function BrightcovePlaylist::extractVideosArray in Brightcove Video Connect 3.x
Same name and namespace in other branches
- 8.2 src/Entity/BrightcovePlaylist.php \Drupal\brightcove\Entity\BrightcovePlaylist::extractVideosArray()
- 8 src/Entity/BrightcovePlaylist.php \Drupal\brightcove\Entity\BrightcovePlaylist::extractVideosArray()
Converts videos from \Brightcove\Item\Playlist to Drupal Field API array.
Parameters
\Brightcove\Item\Playlist $playlist: The playlist whose videos should be extracted.
\Drupal\Core\Entity\EntityStorageInterface $video_storage: Video entity storage.
Return value
array|null The Drupal Field API array that can be saved into a multivalue entity_reference field (like brightcove_playlist.videos), or NULL if the playlist does not have any videos.
Throws
\Exception Thrown when any of the videos is unavailable on the Drupal side.
1 call to BrightcovePlaylist::extractVideosArray()
- BrightcovePlaylist::createOrUpdate in src/
Entity/ BrightcovePlaylist.php - Create or update an existing playlist from a Brightcove Playlist object.
File
- src/
Entity/ BrightcovePlaylist.php, line 680
Class
- BrightcovePlaylist
- Defines the Brightcove Playlist.
Namespace
Drupal\brightcove\EntityCode
protected static function extractVideosArray(Playlist $playlist, EntityStorageInterface $video_storage) {
$videos = $playlist
->getVideoIds();
if (!$videos) {
return NULL;
}
$return = [];
foreach ($playlist
->getVideoIds() as $video_id) {
// Try to retrieve the video from Drupal's brightcove_video storage.
$bcvid = $video_storage
->getQuery()
->condition('video_id', $video_id)
->execute();
if ($bcvid) {
$bcvid = reset($bcvid);
$return[] = [
'target_id' => $bcvid,
];
}
else {
// If the video is not found, then throw this exception, which will
// effectively stop the queue worker, so the playlist with any "unknown"
// video will remain in the queue, so it could be picked up the next
// time hoping the video will be available by then.
throw new \Exception(t('Playlist contains a video that is not (yet) available on the Drupal site'));
}
}
return $return;
}