You are here

function theme_file_entity_file_audio in File Entity (fieldable files) 7.2

Same name and namespace in other branches
  1. 7.3 file_entity.theme.inc \theme_file_entity_file_audio()

Returns HTML for displaying an HTML5 <audio> 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 audio should start playing automatically.
  • loop: Boolean indicating whether or not the audio should loop.
1 theme call to theme_file_entity_file_audio()
file_entity_field_formatter_view in ./file_entity.field.inc
Implements hook_field_formatter_view().

File

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

Code

function theme_file_entity_file_audio($variables) {
  $files = $variables['files'];
  $output = '';
  $audio_attributes = array();
  if ($variables['controls']) {
    $audio_attributes['controls'] = 'controls';
    if (!empty($variables['controls_list'])) {
      $controls_list = array();
      foreach ($variables['controls_list'] as $key => $value) {
        if (!$value) {
          switch ($key) {
            case 'download':
              $controls_list[] = 'nodownload';
              break;
            case 'remote_playback':
              $controls_list[] = 'noremoteplayback';
              break;
          }
        }
      }
      $audio_attributes['controlsList'] = implode(' ', $controls_list);
    }
  }
  if ($variables['autoplay']) {
    $audio_attributes['autoplay'] = 'autoplay';
  }
  if ($variables['loop']) {
    $audio_attributes['loop'] = 'loop';
  }
  if (!empty($variables['preload'])) {
    $audio_attributes['preload'] = $variables['preload'];
  }
  $output .= '<audio' . drupal_attributes($audio_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 .= '</audio>';
  return $output;
}