Problem/Motivation
After the last update I'm not able to upload images.
Steps to reproduce
- Insert Image block
- Click Upload button
- Select file and click open.
- The I'm getting the following error:
Error Log
Location .../editor/media/upload/gutenberg
Message Error: Call to undefined method Drupal\Component\Utility\Bytes::toNumber() in Drupal\gutenberg\MediaUploader->upload() (line 60 of /srv/www/icoewebsite/app/releases/122/web/modules/contrib/gutenberg/src/MediaUploader.php)
#0 /srv/www/icoewebsite/app/releases/122/web/modules/contrib/gutenberg/src/Service/MediaService.php(268): Drupal\gutenberg\MediaUploader->upload()
#1 .../web/modules/contrib/gutenberg/src/Controller/MediaController.php(186): Drupal\gutenberg\Service\MediaService->processMediaEntityUpload()
#2 [internal function]: Drupal\gutenberg\Controller\MediaController->upload()
#3 .../web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array()
#4 .../web/core/lib/Drupal/Core/Render/Renderer.php(573): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#5 .../web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(124): Drupal\Core\Render\Renderer->executeInRenderContext()
#6 .../web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext()
#7 .../vendor/symfony/http-kernel/HttpKernel.php(151): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#8 .../vendor/symfony/http-kernel/HttpKernel.php(68): Symfony\Component\HttpKernel\HttpKernel->handleRaw()
#9 .../web/core/lib/Drupal/Core/StackMiddleware/Session.php(57): Symfony\Component\HttpKernel\HttpKernel->handle()
#10 .../web/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(47): Drupal\Core\StackMiddleware\Session->handle()
#11 .../web/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(47): Drupal\Core\StackMiddleware\KernelPreHandle->handle()
#12 .../web/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(52): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle()
#13 .../vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle()
#14 .../web/core/lib/Drupal/Core/DrupalKernel.php(708): Stack\StackedHttpKernel->handle()
#15 .../web/index.php(19): Drupal\Core\DrupalKernel->handle()
#16 {main}
| Comment | File | Size | Author |
|---|
Issue fork gutenberg-3208986
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
jclopez commentedThe issue is that:
$max_filesize = min(Bytes::toNumber($image_settings['max_size']), Environment::getUploadMaxSize());It won't be supported by Drupal 8, I don't know if we need to check the Drupal version or if the function even exist.
My quick fix was to revert this line to:
$max_filesize = min(Bytes::toInt($image_settings['max_size']), Environment::getUploadMaxSize());The problem with this is that the ToInt() function is deprecated on Drupal 9.
Comment #3
szeidler commentedIt seems to have been introduced recently in #3208407: Don't use a random file name for file uploads.. Not sure what's the best way for keeping backwards compatibility vs. method deprecation. I would vote to keep the deprecated
Bytes::toInt()for a bit longer, even though it's deprecated. Drupal 10 will not come before June 2022 and Drupal 8 will be out of support until then.See https://www.drupal.org/node/3162663 for the related core change.
Comment #5
codebymikey commentedI wasn't particularly proud of the current solution replicating code/API in core, hence this comment, as it could lead to issues like this.
I've created a PR to support both D8 and D9 as we don't want the watchdog log full of deprecation notices.
Comment #7
szeidler commentedThis is a blocker for a new release.
Comment #8
szeidler commentedOops, accidentally uploaded the patch.
I reviewed the MR and it appears to be working for me.
Comment #9
codebymikey commented