You are here

function theme_file_entity_file_video in File Entity (fieldable files) 7.3

Same name and namespace in other branches
  1. 7.2 file_entity.theme.inc \theme_file_entity_file_video()

Returns HTML for displaying an HTML5 <video> tag.

Parameters

array $variables: An associative array containing:

  • file: Associative array of file data, which must include "uri".
  • controls: Boolean indicating whether or not controls should be displayed.
  • autoplay: Boolean indicating whether or not the video should start playing automatically.
  • loop: Boolean indicating whether or not the video should loop.
  • muted: Boolean indicating whether or not the sound should be muted.
  • width: Width, in pixels, of the video player.
  • height: Height, in pixels, of the video player.
  • playsinline: Boolean indicating if video should automatically play on mobile (iOS).
1 theme call to theme_file_entity_file_video()
file_entity_field_formatter_view in ./file_entity.field.inc
Implements hook_field_formatter_view().

File

./file_entity.theme.inc, line 195
Theme callbacks for the file entity module.

Code

function theme_file_entity_file_video($variables) {
  $files = $variables['files'];
  $output = '';
  $video_attributes = array();
  if ($variables['controls']) {
    $video_attributes['controls'] = 'controls';
    if (!empty($variables['controls_list'])) {
      $controls_list = array();
      foreach ($variables['controls_list'] as $key => $value) {
        if (!$value) {
          switch ($key) {
            case 'fullscreen':
              $controls_list[] = 'nofullscreen';
              break;
            case 'download':
              $controls_list[] = 'nodownload';
              break;
            case 'remote_playback':
              $controls_list[] = 'noremoteplayback';
              break;
          }
        }
      }
      $video_attributes['controlsList'] = implode(' ', $controls_list);
    }
  }
  if ($variables['autoplay']) {
    $video_attributes['autoplay'] = 'autoplay';
  }
  if ($variables['loop']) {
    $video_attributes['loop'] = 'loop';
  }
  if ($variables['muted']) {
    $video_attributes['muted'] = 'muted';
  }
  if ($variables['width']) {
    $video_attributes['width'] = $variables['width'];
  }
  if ($variables['height']) {
    $video_attributes['height'] = $variables['height'];
  }
  if (!empty($variables['preload'])) {
    $video_attributes['preload'] = $variables['preload'];
  }
  if ($variables['playsinline']) {
    $video_attributes['playsinline'] = 'playsinline';
  }
  $output .= '<video' . drupal_attributes($video_attributes) . '>';
  foreach ($files as $delta => $file) {
    $source_attributes = array(
      'src' => file_create_url($file['uri']),
      'type' => $file['filemime'],
    );
    $output .= '<source' . drupal_attributes($source_attributes) . ' />';
  }
  $output .= '</video>';
  return $output;
}