FocalPointManager::saveCropEntity(): Argument #3 must be of type int, null given

Created on 22 December 2022, over 1 year ago
Updated 5 April 2023, about 1 year ago

Problem/Motivation

I'm using focal_point in conjunction with Drupal Core 9.5.0 media and PHP 8.1.12. I recently installed the modules media_thumbnails and media_thumbnails_pdf which auto generate a thumbnail for PDF files using imagemagick. The thumbnail generates when I save a media item but I am greeted by a WSOD with the "The website encountered an unexpected error. Please try again later." message. In the log messages I see:

TypeError: Drupal\focal_point\FocalPointManager::saveCropEntity(): Argument #3 ($width) must be of type int, null given, called in /app/web/modules/contrib/focal_point/focal_point.module on line 99 in Drupal\focal_point\FocalPointManager->saveCropEntity() (line 94 of /app/web/modules/contrib/focal_point/src/FocalPointManager.php)

Full trace:

TypeError: Drupal\focal_point\FocalPointManager::saveCropEntity(): Argument #3 ($width) must be of type int, null given, called in /app/web/modules/contrib/focal_point/focal_point.module on line 99 in Drupal\focal_point\FocalPointManager->saveCropEntity() (line 94 of /app/web/modules/contrib/focal_point/src/FocalPointManager.php)
#0 /app/web/modules/contrib/focal_point/focal_point.module(99): Drupal\focal_point\FocalPointManager->saveCropEntity(50.0, 50.0, NULL, NULL, Object(Drupal\crop\Entity\Crop))
#1 [internal function]: focal_point_entity_update(Object(Drupal\media\Entity\Media))
#2 /app/web/core/lib/Drupal/Core/Extension/ModuleHandler.php(426): call_user_func_array(Object(Closure), Array)
#3 /app/web/core/lib/Drupal/Core/Extension/ModuleHandler.php(405): Drupal\Core\Extension\ModuleHandler->Drupal\Core\Extension\{closure}(Object(Closure), 'focal_point')
#4 /app/web/core/lib/Drupal/Core/Extension/ModuleHandler.php(433): Drupal\Core\Extension\ModuleHandler->invokeAllWith('entity_update', Object(Closure))
#5 /app/web/core/lib/Drupal/Core/Entity/EntityStorageBase.php(251): Drupal\Core\Extension\ModuleHandler->invokeAll('entity_update', Array)
#6 /app/web/core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php(903): Drupal\Core\Entity\EntityStorageBase->invokeHook('update', Object(Drupal\media\Entity\Media))
#7 /app/web/core/lib/Drupal/Core/Entity/EntityStorageBase.php(598): Drupal\Core\Entity\ContentEntityStorageBase->invokeHook('update', Object(Drupal\media\Entity\Media))
#8 /app/web/core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php(784): Drupal\Core\Entity\EntityStorageBase->doPostSave(Object(Drupal\media\Entity\Media), true)
#9 /app/web/core/lib/Drupal/Core/Entity/EntityStorageBase.php(523): Drupal\Core\Entity\ContentEntityStorageBase->doPostSave(Object(Drupal\media\Entity\Media), true)
#10 /app/web/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php(804): Drupal\Core\Entity\EntityStorageBase->save(Object(Drupal\media\Entity\Media))
#11 /app/web/core/modules/media/src/MediaStorage.php(29): Drupal\Core\Entity\Sql\SqlContentEntityStorage->save(Object(Drupal\media\Entity\Media))
#12 /app/web/core/lib/Drupal/Core/Entity/EntityBase.php(339): Drupal\media\MediaStorage->save(Object(Drupal\media\Entity\Media))
#13 /app/web/core/lib/Drupal/Core/Entity/EntityForm.php(285): Drupal\Core\Entity\EntityBase->save()
#14 /app/web/core/modules/media/src/MediaForm.php(61): Drupal\Core\Entity\EntityForm->save(Array, Object(Drupal\Core\Form\FormState))
#15 [internal function]: Drupal\media\MediaForm->save(Array, Object(Drupal\Core\Form\FormState))
#16 /app/web/core/lib/Drupal/Core/Form/FormSubmitter.php(114): call_user_func_array(Array, Array)
#17 /app/web/core/lib/Drupal/Core/Form/FormSubmitter.php(52): Drupal\Core\Form\FormSubmitter->executeSubmitHandlers(Array, Object(Drupal\Core\Form\FormState))
#18 /app/web/core/lib/Drupal/Core/Form/FormBuilder.php(595): Drupal\Core\Form\FormSubmitter->doSubmitForm(Array, Object(Drupal\Core\Form\FormState))
#19 /app/web/core/lib/Drupal/Core/Form/FormBuilder.php(323): Drupal\Core\Form\FormBuilder->processForm('media_svg_edit_...', Array, Object(Drupal\Core\Form\FormState))
#20 /app/web/core/lib/Drupal/Core/Controller/FormController.php(73): Drupal\Core\Form\FormBuilder->buildForm(Object(Drupal\media\MediaForm), Object(Drupal\Core\Form\FormState))
#21 [internal function]: Drupal\Core\Controller\FormController->getContentResult(Object(Symfony\Component\HttpFoundation\Request), Object(Drupal\Core\Routing\RouteMatch))
#22 /app/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array(Array, Array)
#23 /app/web/core/lib/Drupal/Core/Render/Renderer.php(580): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#24 /app/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(124): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure))
#25 /app/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array)
#26 /app/vendor/symfony/http-kernel/HttpKernel.php(169): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#27 /app/vendor/symfony/http-kernel/HttpKernel.php(81): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1)
#28 /app/web/core/lib/Drupal/Core/StackMiddleware/Session.php(58): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#29 /app/web/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(48): Drupal\Core\StackMiddleware\Session->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#30 /app/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(106): Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#31 /app/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(85): Drupal\page_cache\StackMiddleware\PageCache->pass(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#32 /app/web/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(48): Drupal\page_cache\StackMiddleware\PageCache->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#33 /app/web/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(51): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#34 /app/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#35 /app/web/core/lib/Drupal/Core/DrupalKernel.php(707): Stack\StackedHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#36 /app/web/index.php(19): Drupal\Core\DrupalKernel->handle(Object(Symfony\Component\HttpFoundation\Request))
#37 {main}.

Steps to reproduce

Install D9.5.
Install focal_point
Upload PDF to Drupal media library.
Install media_thumbnails and media_thumbnails_pdf modules
Go to media library and edit and save the PDF media item
Observe WSOD and error message in logs
Go to media library and see thumbnail indeed generated
Go to /app/web/modules/contrib/focal_point/focal_point.module on line 99 and kint or ksm or dump the $item.
There is no width or height properties because $item is a media item and does not have those properties.

Proposed resolution

Unsure. To be clear though I am not attempting to use focal_point in the generation of the thumbnail so I'm unclear as to why focal_point is even firing?

Remaining tasks

Unsure.

User interface changes

None.

API changes

Unsure.

Data model changes

Unsure.

If I can provide anything further that may be helpful please let me know.

🐛 Bug report
Status

Fixed

Version

2.0

Component

Media Integration

Created by

🇬🇧United Kingdom darren.fisher

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • Status changed to RTBC over 1 year ago
  • 🇵🇹Portugal jcnventura

    I've tested this code on a site running PHP 8.1, that was throwing the error, and after applying the patch in #3, the exception is no longer thrown.

  • 🇨🇦Canada lindsay.wils

    I had the same error, but in a different situation.

    I have a custom media type that I use for handling SVG images. When using a Media reference field and uploading an SVG through the media library modal, upon pressing 'Save and insert' or 'Save and select' this same error was being thrown. I am not getting WSOD, just a JS error, which stops the media item from being attached to the referenced field, but it is actually created, so simple closing, opening again and selected the newly created item works.

    Seemingly the focal point module is trying to apply some default settings to the SVG image, but failing as it cant find a width parameter. Just like the original poster, I do not have the 'Image (Focal Point)' widget selected in my media types form display mode, just the standard Image widget type, so not sure why Focal Point is trying to do anything here.

    This patch also fixes the error for me, thank you.

  • First commit to issue fork.
  • @mandclu opened merge request.
  • 🇨🇦Canada mandclu

    Like @lindsay.wils I ran into this issue while working with an SVG file. I found my own, slightly different fix before finding this issue: instead of passing zeroes into FocalPointManager::saveCropEntity() if item width and/or height are null, I modified the enclosing check for a focal point value to also check for values in the height and width. I personally don't see the value in attempting to apply a focal point to an image that is zero or null in either dimension.

    I also tested the patch in #3 and it did also resolve the fatal errors I was seeing, so I'm not reverted the status to needs review, as any fix at this point would be better than none at all. That said, if anyone in this thread is inclined to test the merge request I've created, it would be appreciated.

  • 🇧🇪Belgium tvb

    I tested merge request !13 and it resolved the issue.

  • 🇺🇸United States PCate

    +1 RTBC. Ran into this issue when uploading an SVG file like @mandclu. Applying merge request !13 solved the issue. Did not test patch #3.

  • 🇦🇹Austria hudri Austria

    I've tested MR !13 sucessfully with svg_image_field module.

    Without this patch I was not able to save media entities because it tried to generate a thumbnail image style. (I guess this is because svg_image_field does return a the SVG uri itself to display previews in the media library widgets, and those thumbnails seem to bypass the default field widget settings).

  • heddn Nicaragua

    +1 on the fix here.

  • 🇺🇸United States loopy1492

    Can also confirm this fixed it for us. Drupal Core 9.5.5, PHP 8.1, Focal Point 2.0.0-alpha2.

  • 🇮🇳India Rajeshreeputra Pune

    can we have test for the same

  • 🇩🇪Germany Anybody Porta Westfalica

    Test might include deleting a file from the file system, which still exists in the database.

  • 🇮🇳India Rajeshreeputra Pune

    Thank you for working on this, merged release will be followed shortly.

  • Status changed to Fixed over 1 year ago
  • 🇮🇳India Sana.Neyazi

    Can anyone please confirm this fixed it for Drupal Core 9.5.7, PHP 8.1, Focal Point 2.0.0-alpha2 as well?

  • Status changed to Fixed about 1 year ago
Production build 0.69.0 2024