1 file.api.php hook_file_formatter_info()

Define file formatters.

Return value

array: An array whose keys are file formatter names and whose values are arrays describing the formatter. Each formatter may contain the following keys:

  • label: The human-readable name for the formatter.
  • default settings: default values for the formatter settings, if any.
  • view callback: a function to call when the formatter is being viewed.
  • settigs callback: a function to call for collecting the settings.
  • hidden: wheter the formatter is hidden or not.
  • mime types: An array of mime types this formatter applies to.

See also

hook_file_formatter_info_alter()

File

core/modules/file/file.api.php, line 88
Hooks for file module.

Code

function hook_file_formatter_info() {
  // Add a simple file formatter for displaying an image in a chosen style.
  if (module_exists('image')) {
    $formatters['file_image'] = array(
      'label' => t('Image'),
      'default settings' => array(
        'image_style' => '',
      ),
      'view callback' => 'file_file_formatter_file_image_view',
      'settings callback' => 'file_file_formatter_file_image_settings',
      'hidden' => TRUE,
      'mime types' => array('image/*'),
    );
  }
  return $formatters;
}