You are here

function html5_media_field_formatter_view in HTML5 Media 7

Implements hook_field_formatter_view().

File

./html5_media.module, line 492

Code

function html5_media_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
  $element = array();
  switch ($display['type']) {
    case 'html5_player':

      // Get the display settings.
      $settings = $display['settings'];

      // Get the ID for this media player.
      $id = 'player-' . drupal_clean_css_identifier($field['field_name']);

      // If they wish to show all sources within a single media element.
      if ($settings['sources']) {

        // Get the media tag.
        $mediatag = '';
        foreach ($items as $delta => $item) {
          if ($mediatag = html5_media_get_media_type((object) $item)) {
            break;
          }
        }

        // If the mediatag exists, then theme the player.
        if ($mediatag) {
          $settings['id'] = $id;
          $element[$delta] = array(
            '#theme' => 'html5_player',
            '#tag' => $mediatag,
            '#attributes' => html5_media_get_attributes($settings),
            '#settings' => $settings,
            '#sources' => $items,
          );
        }
      }
      else {

        // Iterate through all the items.
        foreach ($items as $delta => $item) {

          // Get the media tag.
          if ($mediatag = html5_media_get_media_type((object) $item)) {
            $settings['id'] = $id . '-' . $delta;
            $element[$delta] = array(
              '#theme' => 'html5_player',
              '#tag' => $mediatag,
              '#attributes' => html5_media_get_attributes($settings),
              '#settings' => $settings,
              '#sources' => array(
                $item,
              ),
            );
          }
        }
      }
      break;
  }
  return $element;
}