Problem/Motivation
Deprecated function Error Message when using CKEeditor5 to upload images.
Steps to reproduce
I ran into this error when saving a node. I had just uploaded an image (in this case a gif) and put in a caption with a link and bolded text. These changes were made successfully despite the error.
Deprecated function: str_contains(): Passing null to parameter #1 ($haystack) of type string is deprecated in Drupal\Component\Transliteration\PhpTransliteration->transliterate() (line 135 of core/lib/Drupal/Component/Transliteration/PhpTransliteration.php).
Drupal\Component\Transliteration\PhpTransliteration->transliterate(NULL, 'en', '_') (Line: 57)
Drupal\filename_transliteration\FilenamePostprocessor->process(NULL) (Line: 17)
filename_transliteration_file_field_values_init(Object)
call_user_func_array(Object, Array) (Line: 409)
Drupal\Core\Extension\ModuleHandler->Drupal\Core\Extension\{closure}(Object, 'filename_transliteration') (Line: 388)
Drupal\Core\Extension\ModuleHandler->invokeAllWith('file_field_values_init', Object) (Line: 416)
Drupal\Core\Extension\ModuleHandler->invokeAll('file_field_values_init', Array) (Line: 215)
Drupal\Core\Entity\EntityStorageBase->invokeHook('field_values_init', Object) (Line: 900)
Drupal\Core\Entity\ContentEntityStorageBase->invokeHook('field_values_init', Object) (Line: 283)
Drupal\Core\Entity\ContentEntityStorageBase->initFieldValues(Object, Array) (Line: 129)
Drupal\Core\Entity\ContentEntityStorageBase->doCreate(Array) (Line: 94)
Drupal\Core\Entity\ContentEntityStorageBase->create(Array) (Line: 1139)
Drupal\Core\Entity\ContentEntityBase::create(Array) (Line: 171)
Drupal\ckeditor5\Controller\CKEditor5ImageController->upload(Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 617)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 182)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 76)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 58)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 270)
Drupal\shield\ShieldMiddleware->bypass(Object, 1, 1) (Line: 137)
Drupal\shield\ShieldMiddleware->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object, 1, 1) (Line: 704)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
Deprecated function: mb_convert_encoding(): Passing null to parameter #1 ($string) of type array|string is deprecated in Drupal\Component\Transliteration\PhpTransliteration->transliterate() (line 142 of core/lib/Drupal/Component/Transliteration/PhpTransliteration.php).
Drupal\Component\Transliteration\PhpTransliteration->transliterate(NULL, 'en', '_') (Line: 57)
Drupal\filename_transliteration\FilenamePostprocessor->process(NULL) (Line: 17)
filename_transliteration_file_field_values_init(Object)
call_user_func_array(Object, Array) (Line: 409)
Drupal\Core\Extension\ModuleHandler->Drupal\Core\Extension\{closure}(Object, 'filename_transliteration') (Line: 388)
Drupal\Core\Extension\ModuleHandler->invokeAllWith('file_field_values_init', Object) (Line: 416)
Drupal\Core\Extension\ModuleHandler->invokeAll('file_field_values_init', Array) (Line: 215)
Drupal\Core\Entity\EntityStorageBase->invokeHook('field_values_init', Object) (Line: 900)
Drupal\Core\Entity\ContentEntityStorageBase->invokeHook('field_values_init', Object) (Line: 283)
Drupal\Core\Entity\ContentEntityStorageBase->initFieldValues(Object, Array) (Line: 129)
Drupal\Core\Entity\ContentEntityStorageBase->doCreate(Array) (Line: 94)
Drupal\Core\Entity\ContentEntityStorageBase->create(Array) (Line: 1139)
Drupal\Core\Entity\ContentEntityBase::create(Array) (Line: 171)
Drupal\ckeditor5\Controller\CKEditor5ImageController->upload(Object)
Proposed resolution
The contrib module filename_transliteration is building the filename when initializing the entity and the value is null at that point. Then we also have a hook_presave to do basically the same.
From a functional perspective, these hooks are doing different things:
The first is modifying the filename upon entity initialization.
The second is ensuring that before the file entity is saved, if its name has been changed (or will conflict with another file), it gets a new unique name and updates the related URI.
I see some redundancy from the perspective of transliterating the filename twice (once during initialization and once during pre-save). To avoid this issue we can remove the first hook.
Remaining tasks
User interface changes
API changes
Data model changes