t('Rendered file'),
'description' => t('Display the file in a specific view mode'),
'field types' => array('file', 'image'),
'settings' => array(
'file_view_mode' => 'default',
),
'file formatter' => array(
'hidden' => TRUE,
),
);
$info['file_download_link'] = array(
'label' => t('Download link'),
'description' => t('Displays a link that will force the browser to download the file.'),
'field types' => array('file', 'image'),
'settings' => array(
'text' => t('Download [file:name]'),
),
);
$info['file_audio'] = array(
'label' => t('Audio'),
'description' => t('Render the file using an HTML5 audio tag.'),
'field types' => array('file'),
'settings' => array(
'controls' => TRUE,
'controls_list' => array(
'download' => 'download',
'remote_playback' => 'remote_playback',
),
'autoplay' => FALSE,
'loop' => FALSE,
'preload' => '',
'multiple_file_behavior' => 'tags',
),
'file formatter' => array(
'mime types' => array('audio/*'),
),
);
$info['file_video'] = array(
'label' => t('Video'),
'description' => t('Render the file using an HTML5 video tag.'),
'field types' => array('file'),
'settings' => array(
'controls' => TRUE,
'controls_list' => array(
'fullscreen' => 'fullscreen',
'download' => 'download',
'remote_playback' => 'remote_playback',
),
'autoplay' => FALSE,
'playsinline' => FALSE,
'loop' => FALSE,
'muted' => FALSE,
'width' => NULL,
'height' => NULL,
'preload' => '',
'multiple_file_behavior' => 'tags',
),
'file formatter' => array(
'mime types' => array('video/*'),
),
);
return $info;
}
/**
* Implements hook_field_formatter_info_alter().
*/
function file_entity_field_formatter_info_alter(&$info) {
// Add descriptions to core formatters.
$descriptions = array(
'file_default' => t('Create a simple link to the file. The link is prefixed by a file type icon and the name of the file is used as the link text'),
'file_table' => t('Build a two-column table where the first column contains a generic link to the file and the second column displays the size of the file.'),
'file_url_plain' => t('Display a plain text URL to the file.'),
'image' => t('Format the file as an image. The image can be displayed using an image style and can optionally be linked to the image file itself or its parent content.'),
);
foreach ($descriptions as $key => $description) {
if (isset($info[$key]) && empty($info[$key]['description'])) {
$info[$key]['description'] = $description;
}
}
// Formatters that can be used for images but not files, should have a
// default mimetype restriction added to the image/* mime type for use with
// file formatters.
foreach ($info as &$formatter) {
if (!isset($formatter['file formatter']) && in_array('image', $formatter['field types']) && !in_array('file', $formatter['field types'])) {
$formatter['file formatter']['mime types'] = array('image/*');
}
}
}
/**
* Implements hook_field_formatter_settings_form().
*/
function file_entity_field_formatter_settings_form($field, $instance, $view_mode, $form, &$form_state) {
$display = $instance['display'][$view_mode];
$settings = $display['settings'];
$element = array();
if ($display['type'] == 'file_rendered') {
$element['file_view_mode'] = array(
'#title' => t('View mode'),
'#type' => 'select',
'#options' => file_entity_view_mode_labels(),
'#default_value' => $settings['file_view_mode'],
// Never empty, so no #empty_option
);
}
elseif ($display['type'] == 'file_download_link') {
$element['text'] = array(
'#type' => 'textfield',
'#title' => t('Link text'),
'#description' => t('This field support tokens.'),
'#default_value' => $settings['text'],
'#required' => TRUE,
);
}
elseif ($display['type'] == 'file_audio') {
$element['controls'] = array(
'#title' => t('Show audio controls'),
'#type' => 'checkbox',
'#default_value' => $settings['controls'],
);
$element['controls_list'] = array(
'#title' => t('Controls list'),
'#type' => 'checkboxes',
'#options' => array(
'download' => t('Download'),
'remote_playback' => t('Remote playback'),
),
'#default_value' => $settings['controls_list'],
'#description' => t("Customize native media controls such as the download and remoteplayback buttons. Valid only if above \"Show audio controls\" setting is enabled.
Please note that not all browsers support this feature. Only Chrome 58+ and Opera 45+ supports it."),
);
$element['autoplay'] = array(
'#title' => t('Autoplay'),
'#type' => 'checkbox',
'#default_value' => $settings['autoplay'],
);
$element['loop'] = array(
'#title' => t('Loop'),
'#type' => 'checkbox',
'#default_value' => $settings['loop'],
);
$element['preload'] = array(
'#title' => t('Preload'),
'#type' => 'select',
'#default_value' => $settings['preload'],
'#options' => drupal_map_assoc(array('none', 'auto', 'metadata')),
'#empty_option' => 'unspecified',
);
$element['multiple_file_behavior'] = array(
'#title' => t('Display of multiple files'),
'#type' => 'radios',
'#options' => array(
'tags' => t('Use multiple @tag tags, each with a single source', array('@tag' => '