function geofield_map_preprocess_select in Geofield Map 8.2
Implements hook_preprocess_HOOK().
File
- ./
geofield_map.module, line 222 - Contains the geofield_map.module.
Code
function geofield_map_preprocess_select(&$variables) {
$element = $variables['element'];
if (!empty($element['#geofield_map_marker_icon_select']) && !empty($element['#value']) && $element['#value'] != 'none') {
/* @var \Drupal\Core\Image\Image $image */
$image = \Drupal::service('image.factory')
->get($element['#value']);
$file_width = $file_height = 1;
if ($image
->isValid()) {
$file_width = $image
->getWidth();
$file_height = $image
->getHeight();
}
$image_preview_width = 44;
$image_preview_height = $image_preview_width * $file_width / $file_height;
$element['preview'] = [
'#weight' => -10,
'#theme' => 'image',
'#width' => $image_preview_width,
'#height' => $image_preview_height,
'#uri' => file_create_url($element['#value']),
];
$variables['data'] = [];
foreach (Element::children($element) as $child) {
$variables['data'][$child] = $element[$child];
}
}
}