function file_displays in D7 Media 7
Returns an array of possible displays to use for a file type in a given view mode.
It is common for a site to be configured with broadly defined file types (e.g., 'video'), and to have different files of this type require different displays (for example, the code required to display a YouTube video is different than the code required to display a local QuickTime video). Therefore, the site administrator can configure multiple displays for a given file type. This function returns all of the displays that the administrator enabled for the given file type in the given view mode. file_view_file() then invokes each of these, and passes the specific file to display. Each display implementation can inspect the file, and either return a render array (if it is capable of displaying the file), or return nothing (if it is incapable of displaying the file). The first render array returned is the one used.
Parameters
$file_type: The type of file.
$view_mode: The view mode.
Return value
An array keyed by the formatter type name. Each item in the array contains the following key/value pairs:
- status: Whether this display is enabled. If not TRUE, file_view_file() skips over it.
- weight: An integer that determines the order of precedence within the returned array. The lowest weight display capable of displaying the file is used.
- settings: An array of key/value pairs specific to the formatter type. See hook_file_formatter_info() for details.
See also
1 call to file_displays()
- file_view_file in file_entity/
file_entity.file_api.inc - Generate an array for rendering just the file portion of a file entity.
2 string references to 'file_displays'
- file_entity_update_7001 in file_entity/
file_entity.install - Move file display configurations from the 'file_displays' variable to the {file_display} database table.
- media_update_7016 in ./
media.install - Convert Media entities to File entities.
File
- file_entity/
file_entity.file_api.inc, line 302 - API extensions of Drupal core's file.inc.
Code
function file_displays($file_type, $view_mode = 'default') {
$cache =& drupal_static(__FUNCTION__, array());
// If the requested view mode isn't configured to use a custom display for its
// fields, then don't use a custom display for its file either.
if ($view_mode != 'default') {
$view_mode_settings = field_view_mode_settings('file', $file_type);
$view_mode = !empty($view_mode_settings[$view_mode]['custom_settings']) ? $view_mode : 'default';
}
if (!isset($cache[$file_type][$view_mode])) {
// Load the display configurations for the file type and view mode. If none
// exist for the view mode, use the default view mode.
$displays = file_displays_load($file_type, $view_mode, TRUE);
if (empty($displays) && $view_mode != 'default') {
$cache[$file_type][$view_mode] = file_displays($file_type, 'default');
}
else {
// Convert the display objects to arrays and remove unnecessary keys.
foreach ($displays as $formatter_name => $display) {
$displays[$formatter_name] = array_intersect_key((array) $display, drupal_map_assoc(array(
'status',
'weight',
'settings',
)));
}
$cache[$file_type][$view_mode] = $displays;
}
}
return $cache[$file_type][$view_mode];
}