function managed_file_element_preview in Managed File 7
Add image preview to managed file.
@internal
Parameters
array $element: Form element to process.
Return value
array Processed element.
1 string reference to 'managed_file_element_preview'
- managed_file_element_process in includes/
managed_file.common.inc - Process widget of managed file.
File
- includes/
managed_file.common.inc, line 252 - Auxiliary functionality.
Code
function managed_file_element_preview(array $element) {
if (empty($element['#file'])) {
hide($element['remove_button']);
}
else {
$file = $element['#file'];
hide($element['upload']);
hide($element['upload_button']);
if (!file_validate_is_image($file)) {
$info = image_get_info($file->uri);
$variables = [
'alt' => $file->filename,
'path' => $file->uri,
'style_name' => 'thumbnail',
'attributes' => [
'class' => [
'upload-preview',
],
],
];
if (is_array($info)) {
$variables += $info;
}
$element['preview'] = [
'#type' => 'markup',
'#weight' => -10,
'#markup' => theme('image_style', $variables),
];
}
}
return $element;
}