You are here

function brightcove_brightcove_playlist_view in Brightcove Video Connect 8

Same name and namespace in other branches
  1. 8.2 brightcove.module \brightcove_brightcove_playlist_view()
  2. 3.x brightcove.module \brightcove_brightcove_playlist_view()

Implements hook_ENTITY_TYPE_view().

File

./brightcove.module, line 249
Brightcove module.

Code

function brightcove_brightcove_playlist_view(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display, $view_mode) {
  if ($display
    ->getComponent('brightcove_playlist_video_player')) {

    /** @var \Drupal\brightcove\Entity\BrightcovePlaylist $playlist_entity */
    $playlist_entity = $entity;

    // Only display the video player if we have all the info needed for it.
    if ($playlist_id = $playlist_entity
      ->getPlaylistId()) {

      /** @var \Drupal\brightcove\Entity\BrightcoveApiClient $api_client */
      $api_client = BrightcoveUtil::getApiClient($playlist_entity
        ->getApiClient());

      /** @var \Drupal\brightcove\Entity\BrightcovePlayer $player */
      if ($player = $playlist_entity
        ->getPlayer()) {
        $player = BrightcovePlayer::load($player);
      }
      if (!$player) {
        $player = BrightcovePlayer::loadByPlayerId($api_client
          ->getDefaultPlayer());
      }
      $build['brightcove_playlist_video_player'] = [
        '#theme' => [
          'brightcove_playlist_video_player',
        ],
        '#playlist_id' => $playlist_id,
        '#account' => $api_client
          ->getAccountId(),
        '#player' => BrightcoveUtil::getDefaultPlayer($playlist_entity),
        '#height' => !empty($player) ? $player
          ->getHeight() : NULL,
        '#width' => !empty($player) ? $player
          ->getWidth() : NULL,
        '#data_usage' => 'cms:drupal:' . \DRUPAL::VERSION . ':' . system_get_info('module', 'brightcove')['version'] . ':javascript',
      ];
    }
  }
}