function template_preprocess_image_browser in Image Entity Browser 8
Implements hook template_preprocess_theme().
File
- ./
image_browser.module, line 20 - Extends Drupal file entities to be fieldable and viewable.
Code
function template_preprocess_image_browser(&$variables) {
$element = $variables['element'];
if (!isset($element['#value']) && isset($element['#default_value'])) {
$element['#value'] = $element['#default_value'];
}
// Remove name attribute if empty, for W3C compliance.
if (isset($variables['attributes']['name']) && empty((string) $variables['attributes']['name'])) {
unset($variables['attributes']['name']);
}
if (isset($element['#value'])) {
$fid = str_replace('file:', '', $element['#value']);
if ($file = File::load($fid)) {
if ($file
->getMimeType() == 'image/svg+xml') {
$variables['preview'] = array(
'#markup' => '<img src="' . file_create_url($file
->getFileUri()) . '" style="max-width: 100px"/>',
);
}
else {
$variables['preview'] = array(
'#theme' => 'image_style',
'#style_name' => 'image_browser_thumbnail',
'#uri' => $file
->getFileUri(),
);
}
}
}
$variables['children'] = $element['#children'];
$variables['html_id'] = \Drupal\Component\Utility\Html::getUniqueId('dexp-image-browser');
}