1 file.module file_display($file_type, $view_mode)

Returns an array containing a single display to use for a file type in a given view mode.

Parameters

string $file_type: The type of file.

string $view_mode: The view mode.

Return value

array: An array containing 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

hook_file_formatter_info()

file_view_file()

Related topics

File

core/modules/file/file.module, line 2140
Defines a "managed_file" Form API field and a "file" field for Field module.

Code

function file_display($file_type, $view_mode) {
  $cache = &backdrop_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 configuration for the file type and view mode. If none
    // exist for the view mode, use the default view mode.
    $display = file_display_load($file_type, $view_mode);
    if (empty($display) && $view_mode != 'default') {
      $cache[$file_type][$view_mode] = file_display($file_type, 'default');
    }
    else {
      $cache[$file_type][$view_mode] = $display;
    }
  }

  return $cache[$file_type][$view_mode];
}