- 🇷🇴Romania reszli Târgu Mureș
In my case, it was not possible to achive Multi-byte UTF-8 support on the server, so I needed to work around it
My solution was to replace the original YouTube provider with a custom one that extends the original one and strips non-ASCII characters form the filename on preSave() method.add these hook implementations to mymodule.module file
/** * Implements hook_media_internet_providers_alter(). */ function mymodule_media_media_internet_providers_alter(&$providers) { unset($providers['MediaInternetYouTubeHandler']); } /** * Implements hook_media_internet_providers(). */ function mymodule_media_media_internet_providers() { return [ 'MymoduleMediaInternetYouTubeHandler' => [ 'title' => t('YouTube'), 'module' => 'mymodule', 'weight' => 3, ], ]; }
create a new file under mymodule/includes/MymoduleMediaInternetYouTubeHandler.inc with the following content:
/** * @file * Extends the MediaInternetYouTubeHandler class to handle YouTube videos. */ /** * Implementation of MediaInternetBaseHandler. * * @see hook_media_internet_providers(). */ class MymoduleMediaInternetYouTubeHandler extends MediaInternetYouTubeHandler { /** * Before the file has been saved, implementors may do additional operations. * * @param object $file_obj */ public function preSave(&$file_obj) { parent::preSave($file_obj); // Remove non-ASCII characters from the filename. $file_obj->filename = trim(preg_replace('/[^\x20-\x7E]/','', $file_obj->filename)); } }
- Status changed to Fixed
over 1 year ago 2:10pm 12 May 2023 - 🇳🇴Norway steinmb
That should work :) - I'll going to close this. Only one post in 6 years :)
Automatically closed - issue fixed for 2 weeks with no activity.