- Issue created by @jorgik
- 🇫🇷France mably
I have followed the steps indicated but have not been unable to reproduce the problem.
Though I was on Drupal 11.1. Could it be a Drupal 10 specific issue?
- 🇵🇱Poland jorgik
My current setup is 10.4.5, also same issue happens inside paragraphs, when svg_image part of the paragraphs' entity which is part of node
- 🇵🇱Poland jorgik
Unable to reproduce on 10.3.14, maybe related to focal point that also on the project I have. Anyway, could be useful to have own validator
- 🇫🇷France mably
Nice works, thanks!
Tested successfully.
What is interesting is that it will make this module compatible with Image Widget Crop → .
We will only need to add this simple hook to make it work:
/** * Implements hook_field_widget_single_element_form_alter(). */ function svg_image_field_widget_single_element_form_alter(&$element, &$form_state, $context) { if ($context['widget'] instanceof ImageWidget && !$context['widget'] instanceof SvgImageWidget) { $field_definition = $context['items']->getFieldDefinition(); $field_settings = $field_definition->getSettings(); $allowed_extensions = explode(' ', $field_settings['file_extensions']); if (in_array('svg', $allowed_extensions)) { $extensions = explode(' ', $element['#upload_validators']['FileExtension']['extensions']); if (!in_array('svg', $extensions)) { $extensions[] = 'svg'; $element['#upload_validators']['FileExtension']['extensions'] = implode(' ', $extensions); } } $class = '\Drupal\svg_image\Plugin\Field\FieldWidget\SvgImageWidget'; $element['#process'] = array_merge($element['#process'], [[$class, 'process']]); } }
Will create a separate issue for it.