function svg_image_preprocess_image_style in Svg Image 8
Same name and namespace in other branches
- 7 svg_image.module \svg_image_preprocess_image_style()
- 2.x svg_image.module \svg_image_preprocess_image_style()
- 1.x svg_image.module \svg_image_preprocess_image_style()
Prepares variables for image style templates.
This is a workaround till full/partial images styles support will be added. It allows to still display the original SVG image with a special class, so you can adjust width/height at least.
See also
template_preprocess_image_style()
File
- ./
svg_image.module, line 37 - Contains main functions and hooks for svg_image module.
Code
function svg_image_preprocess_image_style(array &$variables) {
if (isset($variables['image']['#access']) && !$variables['image']['#access'] && !empty($variables['image']['#uri'])) {
$files = \Drupal::entityTypeManager()
->getStorage('file')
->loadByProperties([
'uri' => $variables['uri'],
]);
if ($files) {
$imageFile = reset($files);
if (svg_image_is_file_svg($imageFile)) {
$variables['image']['#access'] = TRUE;
$variables['image']['#attributes']['class'][] = 'no-image-style';
}
}
}
}