Filename sanitization settings
Site builders are now able to opt-in for various forms of filename sanitization on admin/config/media/file-system:
- Transliterate the filename. Disabled by default, because it's not useful for some languages like Japanese.
- Replace whitespace with dash (
-) or underscore (_). - Replace any characters other than 0-9A-Za-z or
-or_or.with dash (-) or underscore (_). - Remove duplicate separator characters ie
--or..or__with be replaced with-or.or_. - Convert to lowercase (to prevent issues on case-insensitive file systems).
Example values for file.settings config settings::
filename_sanitization:
transliterate: true
replace_whitespace: '-'
replace_non_alphanumeric: ' '
dedupe_separators: true
lowercase: true
FileUploadSanitizeNameEvent dispatched during file upload
Core now dispatches a \Drupal\file\Event\FileUploadSanitizeNameEvent whenever a file is uploaded (either via the UI or via REST). Event subscribers can modify and sanitize the filename (but not extension) before the file is saved.
Changes to the FileUploadResource plugin constructor
To properly support the new FileUploadSanitizeNameEvent during REST uploads \Drupal\file\Plugin\rest\FileUploadResource::__construct() takes 2 new arguments for additional service dependencies:
/**
...
* @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $event_dispatcher
* The event dispatcher service.
* @param \Drupal\Core\Language\LanguageManagerInterface $language_manager
* The language manager service.
*/
These arguments are optional for now, but not defining them is deprecated and any classes that extend FileUploadResource or code that calls the constructor directly should be updated to use proper dependency injection before 11.0.0.
Comments
transliterate_filenames module
If you're using the transliterate_filenames module, see this issue and please help to switch over: https://www.drupal.org/project/transliterate_filenames/issues/3385940
http://www.DROWL.de || Professionelle Drupal Lösungen aus Ostwestfalen-Lippe (OWL)
http://www.webks.de || webks: websolutions kept simple - Webbasierte Lösungen die einfach überzeugen!
http://www.drupal-theming.com || Individuelle Responsive Themes
filename_transliteration module
If, on the other hand, you're using the filename_transliteration module, see this issue and please help to switch over https://www.drupal.org/project/filename_transliteration/issues/3238461