You are here

function brightcove_media_playlist_list in Brightcove Video Connect 7.7

Same name and namespace in other branches
  1. 7.4 brightcove_media/brightcove_media.module \brightcove_media_playlist_list()
  2. 7.6 brightcove_media/brightcove_media.module \brightcove_media_playlist_list()

brightcove/media/playlist/list menu callback function.

1 string reference to 'brightcove_media_playlist_list'
brightcove_media_menu in brightcove_media/brightcove_media.module
Implements hook_menu().

File

brightcove_media/brightcove_media.module, line 751
This module provide the hook implementations for the integration with Media module.

Code

function brightcove_media_playlist_list() {
  module_load_include('browser.inc', 'media', 'includes/media');
  $media = [];
  $files = [];
  $default_items_per_page = 20;
  $params = drupal_get_query_parameters();
  $limit = isset($params['limit']) ? $params['limit'] : $default_items_per_page;
  $page = isset($params['start']) ? ceil($params['start'] / $limit) : 0;
  $client = brightcove_client_load_or_default();

  /** @var \Brightcove\Object\Playlist[] $playlists */
  $playlists = brightcove_get_playlists($client, 'name', $page);
  if (is_array($playlists) && count($playlists)) {
    foreach ($playlists as $playlist) {
      $uri = file_stream_wrapper_uri_normalize("brightcove-playlist://{$playlist->getId()}");
      $file = file_uri_to_object($uri);
      $file->filename = $playlist
        ->getName();
      $file->type = 'video';
      if (!isset($file->fid)) {
        $file->fid = 0;
      }
      media_browser_build_media_item($file);
      $file->preview = l($file->preview, 'media/browser', [
        'html' => TRUE,
        'attributes' => [
          'data-uri' => $uri,
        ],
        'query' => [
          'render' => 'media-popup',
          'uri' => $uri,
        ],
      ]);
      $files[$uri] = $file;
      $media[] = $file;
    }
  }
  drupal_add_js([
    'brightcove_playlist' => [
      'files' => $files,
    ],
  ], 'setting');
  drupal_json_output($media);
}