You are here

function brightcove_brightcove_video_view in Brightcove Video Connect 8.2

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

Implements hook_ENTITY_TYPE_view().

File

./brightcove.module, line 195
Brightcove module.

Code

function brightcove_brightcove_video_view(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display, $view_mode) {

  /** @var \Drupal\brightcove\Entity\BrightcoveVideo $entity */
  if ($display
    ->getComponent('brightcove_player')) {
    $build['brightcove_player'] = _brightcove_get_player_field($entity);
  }
  if ($display
    ->getComponent('brightcove_custom_fields')) {
    $custom_fields = BrightcoveCustomField::loadMultipleByApiClient($entity
      ->getApiClient());

    // Show custom fields in the extra field, if it exists and has a value.
    $custom_field_values = $entity
      ->getCustomFieldValues();
    $build['brightcove_custom_fields'] = [];
    foreach ($custom_fields as $custom_field) {
      $custom_field_id = $custom_field
        ->getCustomFieldId();
      if (empty($custom_field_values[$custom_field_id])) {
        continue;
      }
      $build['brightcove_custom_fields'][$custom_field_id] = [
        '#type' => 'item',
        '#title' => $custom_field
          ->getName(),
        '#markup' => $custom_field_values[$custom_field_id],
      ];
    }
  }
}