media_entity_audio.module in Media entity audio 8
Same filename and directory in other branches
Media entity for audio files.
File
media_entity_audio.moduleView source
<?php
/**
* @file
* Media entity for audio files.
*/
use Drupal\file\Entity\File;
/**
* Implements hook_theme().
*/
function media_entity_audio_theme() {
return array(
'media_audio_file_formatter' => array(
'variables' => array(
'file' => NULL,
'description' => NULL,
'attributes' => array(),
'value' => NULL,
'extravalue' => NULL,
),
),
);
}
/**
* Implements template_preprocess_media_audio_file_formatter().
*/
function media_entity_audio_preprocess_media_audio_file_formatter(&$vars) {
$file = $vars['file'];
$file_entity = $file instanceof File ? $file : File::load($file->fid);
$url = file_create_url($file_entity
->getFileUri());
$mimetype = $file_entity
->getMimeType();
if ($mimetype == 'audio/mpeg') {
$vars['mimetype'] = 'audio/mpeg';
}
if ($mimetype == 'audio/x-wav') {
$vars['mimetype'] = 'audio/wav';
}
if ($mimetype == 'audio/ogg') {
$vars['mimetype'] = 'audio/ogg';
}
$vars['media_link'] = $url;
}
Functions
Name | Description |
---|---|
media_entity_audio_preprocess_media_audio_file_formatter | Implements template_preprocess_media_audio_file_formatter(). |
media_entity_audio_theme | Implements hook_theme(). |