function picture_file_formatter_picture_view in Picture 7
Same name and namespace in other branches
- 7.2 picture.file_entity_1.inc \picture_file_formatter_picture_view()
'view callback' for hook_file_formatter_info().
1 string reference to 'picture_file_formatter_picture_view'
- picture_file_formatter_info in ./
picture.file_entity_1.inc - Implements hook_file_formatter_info().
File
- ./
picture.file_entity_1.inc, line 30 - Hooks and functions to support version 1 of the File Entity module.
Code
function picture_file_formatter_picture_view($file, $display, $langcode) {
// Prevent PHP notices when trying to read empty files.
// @see http://drupal.org/node/681042
if (!$file->filesize) {
return;
}
// Do not bother proceeding if this file does not have an image mime type.
if (strpos($file->filemime, 'image/') !== 0) {
return;
}
$scheme = file_uri_scheme($file->uri);
$wrappers = file_get_stream_wrappers(STREAM_WRAPPERS_READ);
$readable = !empty($wrappers[$scheme]);
if ($readable) {
$fallback_image_style = '';
$group_name = $display['settings']['picture_group'];
$mappings = picture_mapping_load($group_name);
$breakpoint_styles = picture_get_mapping_breakpoints($mappings, $fallback_image_style);
if (isset($display['settings']['fallback_image_style']) && !empty($display['settings']['fallback_image_style'])) {
$fallback_image_style = $display['settings']['fallback_image_style'];
}
if (isset($file->override) && isset($file->override['wysiwyg']) && $file->override['wysiwyg']) {
return array(
'#theme' => 'image_style',
'#style_name' => $fallback_image_style,
'#path' => $file->uri,
);
}
$replace_options = array(
'clear' => 1,
'sanitize' => 0,
);
$dimensions = array(
'width' => '',
'height' => '',
);
if (isset($file->image_dimensions['width'])) {
$dimensions['width'] = $file->image_dimensions['width'];
}
elseif (isset($file->metadata['width'])) {
$dimensions['width'] = $file->metadata['width'];
}
if (isset($file->image_dimensions['height'])) {
$dimensions['height'] = $file->image_dimensions['height'];
}
elseif (isset($file->metadata['height'])) {
$dimensions['height'] = $file->metadata['height'];
}
$element = array(
'#theme' => 'picture_formatter',
'#attached' => array(
'library' => array(
array(
'picture',
'matchmedia',
),
array(
'picture',
'picturefill',
),
array(
'picture',
'picture.ajax',
),
),
),
'#item' => array(
'style_name' => $fallback_image_style,
'path' => $file->uri,
'uri' => $file->uri,
'alt' => token_replace($display['settings']['alt'], array(
'file' => $file,
), $replace_options),
'title' => token_replace($display['settings']['title'], array(
'file' => $file,
), $replace_options),
) + $dimensions,
'#image_style' => $fallback_image_style,
'#breakpoints' => $breakpoint_styles,
'#path' => '',
);
return $element;
}
}