1 file.api.php | hook_file_formatter_FORMATTER_view($file, $display, $langcode) |
Define formatter output.
Note: This is not really a hook. The function name is manually specified via 'view callback' in hook_file_formatter_info(), with this recommended callback name pattern.
Parameters
object $file: The file entity.
array $display: An array containing settings for how to display the file.
string $langcode: A language code indicating the language used to render the file.
File
- core/
modules/ file/ file.api.php, line 130 - Hooks for file module.
Code
function hook_file_formatter_FORMATTER_view($file, $display, $langcode) {
$element = array(
'#theme' => 'image',
'#path' => $file->uri,
'#width' => isset($file->override['attributes']['width']) ? $file->override['attributes']['width'] : $file->metadata['width'],
'#height' => isset($file->override['attributes']['height']) ? $file->override['attributes']['height'] : $file->metadata['height'],
'#alt' => token_replace($display['settings']['alt'], array('file' => $file), $replace_options),
'#title' => token_replace($display['settings']['title'], array('file' => $file), $replace_options),
);
return $element;
}