You are here

function jw_player_field_formatter_view in JW Player 7

Same name and namespace in other branches
  1. 7.2 jw_player.module \jw_player_field_formatter_view()

Implements hook_field_formatter_view().

File

./jw_player.module, line 158
Adds a theme function which allows theme developers to use the JW Player.

Code

function jw_player_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
  $element = array();
  if ($display['type'] == 'jw_player') {

    // Process files for the theme function.
    $files = array();
    foreach ($items as $delta => $item) {
      $files[$delta] = (object) $item;
    }
    foreach ($files as $delta => $file) {

      // Give each instance of the player a unique id. The combination
      // of fid and preset are considered to be save even in cases where
      // the entire theme functions output is cached.
      // Prefixing the id makes sure that the id does not start with a
      // invalid numeric value.
      $id = $file->fid . $display['settings']['jwplayer_preset'];
      $element[$delta] = array(
        '#theme' => 'jw_player',
        '#file_object' => $file,
        '#preset' => $display['settings']['jwplayer_preset'],
        '#html_id' => drupal_html_id('jwplayer' . $id),
      );
    }
  }
  return $element;
}