You are here

function brightcove_field_field_formatter_view in Brightcove Video Connect 7.5

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

Implements hook_field_formatter_view().

Parameters

$entity_type:

$entity:

$field:

$instance:

$langcode:

$items:

$display:

Return value

array

File

brightcove_field/brightcove_field.module, line 1335
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 = NULL;
  $variables = array();
  $settings = $display['settings'];
  $variables['#brightcove_widget_type'] = $instance['widget']['type'];
  if ($display['type'] == 'brightcove_default') {
    $theme = 'brightcove_field_formatter_default';
  }
  if ($display['type'] == 'brightcove_image') {
    $theme = 'brightcove_field_image';
    $variables['#brightcove_image_style'] = $settings['brightcove_image_style'];
    $variables['#brightcove_image_link'] = $settings['brightcove_image_link'];
    $variables['#brightcove_image_type'] = $settings['brightcove_image_type'];
  }
  if ($display['type'] == 'brightcove_metadata') {
    $metadata_options = _brightcove_field_get_object_formatter_keys();
    $theme = 'brightcove_field_metadata';
    $variables['#key'] = $settings['brightcove_metadata_type'];
    $variables['#label'] = $metadata_options[$settings['brightcove_metadata_type']];
  }
  if (isset($settings['brightcove_image_link']) && $settings['brightcove_image_link'] == 'dialog') {
    $variables['#attached']['library'][] = array(
      'system',
      'drupal.ajax',
    );
    $variables['#attached']['library'][] = array(
      'system',
      'ui.dialog',
    );
    $variables['#attached']['js'][] = drupal_get_path('module', 'brightcove_field') . '/js/brightcove.js';
    $variables['#attached']['css'][] = drupal_get_path('module', 'brightcove_field') . '/styles/brightcove.css';
  }
  if ($theme) {
    switch ($instance['widget']['type']) {
      case BRIGHTCOVE_VIDEO_WIDGET:
        foreach ($items as $delta => $item) {
          $video = FALSE;
          if (isset($item['brightcove_id'])) {
            $video = brightcove_video_load($item['brightcove_id']);
          }
          $element[$delta] = array(
            '#theme' => $theme,
            '#type' => 'brightcove',
            '#element' => $item,
            '#delta' => $delta,
            '#entity_type' => $entity_type,
            '#entity' => $entity,
            '#field' => $field,
            '#instance' => $instance,
            '#display' => $display,
            '#video' => $video,
            '#width' => isset($settings['width']) ? $settings['width'] : NULL,
            '#height' => isset($settings['height']) ? $settings['height'] : NULL,
          ) + $variables;
        }
        break;
      case BRIGHTCOVE_PLAYLIST_WIDGET:
        foreach ($items as $delta => $item) {
          $playlist = FALSE;
          if (isset($item['brightcove_id'])) {
            $playlist = brightcove_playlist_load($item['brightcove_id']);
          }
          $element[$delta] = array(
            '#theme' => $theme,
            '#type' => 'brightcove-player',
            '#element' => $item,
            '#delta' => $delta,
            '#entity_type' => $entity_type,
            '#entity' => $entity,
            '#field' => $field,
            '#instance' => $instance,
            '#display' => $display,
            '#playlist' => $playlist,
            '#width' => isset($settings['width']) ? $settings['width'] : NULL,
            '#height' => isset($settings['height']) ? $settings['height'] : NULL,
          ) + $variables;
        }
        break;
    }
  }
  return $element;
}