You are here

function brightcove_field_field_formatter_view in Brightcove Video Connect 7.2

Same name and namespace in other branches
  1. 7.3 brightcove_field/brightcove_field.module \brightcove_field_field_formatter_view()
  2. 7.4 brightcove_field/brightcove_field.module \brightcove_field_field_formatter_view()
  3. 7.5 brightcove_field/brightcove_field.module \brightcove_field_field_formatter_view()

Implements hook_field_formatter_view().

File

brightcove_field/brightcove_field.module, line 1281
Brightcove field module provides a Content Construction Kit module to developers, allowing them to browse videos in their Brightcove Studio and upload them.

Code

function brightcove_field_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
  $element = array();
  $theme = '';
  $variables = array();
  $settings = $display['settings'];
  if ($display['type'] == 'default') {
    $theme = 'brightcove_field_formatter_default';
  }
  if (in_array($display['type'], array(
    'entity_link_videoStillURL',
    'entity_link_thumbnailURL',
    'entity_image_videoStillURL',
    'entity_image_thumbnailURL',
    'dialog_player_videoStillURL',
    'dialog_player_thumbnailURL',
  ))) {
    $theme = "brightcove_field_formatter_{$display['type']}";
    $variables['#image'] = '';
    $variables['#style'] = '';
  }
  foreach (image_styles() as $style) {
    if (in_array($display['type'], array(
      "dialog_{$style['name']}__thumbnailURL",
      "dialog_{$style['name']}__videoStillURL",
      "entity_link_{$style['name']}__thumbnailURL",
      "entity_link_{$style['name']}__videoStillURL",
      "entity_image_{$style['name']}__thumbnailURL",
      "entity_image_{$style['name']}__videoStillURL",
    ))) {
      $theme = "brightcove_field_formatter_{$display['type']}";
    }
  }
  foreach (_brightcove_field_get_object_formatter_keys() as $key => $label) {
    if ($display['type'] == "brightcove_metadata_{$key}") {
      $theme = 'brightcove_field_formatter_metadata';
      $variables['#key'] = $key;
      $variables['#label'] = $label;
    }
  }
  if (strpos($display['type'], 'dialog') === 0) {
    $variables['#attached']['js'][] = 'misc/ajax.js';
    $variables['#attached']['js'][] = drupal_get_path('module', 'brightcove_field') . '/js/brightcove.js';
    $variables['#attached']['library'][] = array(
      'system',
      'ui.dialog',
    );
    $variables['#attached']['css'][] = drupal_get_path('module', 'brightcove_field') . '/styles/brightcove.css';
  }
  if ($theme) {
    foreach ($items as $delta => $item) {
      $element[$delta] = array(
        '#theme' => $theme,
        '#element' => $item,
        '#delta' => $delta,
        '#entity_type' => $entity_type,
        '#entity' => $entity,
        '#field' => $field,
        '#instance' => $instance,
        '#display' => $display,
        '#video' => brightcove_video_load($item['video_id']),
        '#width' => isset($settings['width']) ? $settings['width'] : NULL,
        '#height' => isset($settings['height']) ? $settings['height'] : NULL,
      ) + $variables;
    }
  }
  return $element;
}