1

I have a plugin that allows the user to upload an image using managed_file to use as a bg image. While using the In-Place editor, I get a Ajax 500 error when trying to upload. I will post my watchdog log below. When trying to edit the same page via admin>structure>pages>content, I am able to do this perfectly fine. It also seems that, after uploading the file in admin>structure>pages>content, I am able to swap this image on this block plugin using the in place editor, but trying to do this initially with the in place editor fails.

Watchdog:

a:6:{s:5:"%type";s:9:"Exception";s:8:"@message";s:84:"Serialization of 'Symfony\Component\HttpFoundation\File\UploadedFile' is not allowed";s:9:"%function";s:11:"serialize()";s:5:"%file";s:89:"/var/www/my_domain/web/core/lib/Drupal/Component/Serialization/PhpSerialize.php";s:5:"%line";i:14;s:17:"@backtrace_string";s:4943:"#0 /var/www/my_domain/web/core/lib/Drupal/Component/Serialization/PhpSerialize.php(14): serialize(Array)
#1 /var/www/my_domain/web/core/lib/Drupal/Core/KeyValueStore/DatabaseStorageExpirable.php(81): Drupal\Component\Serialization\PhpSerialize::encode(Array)
#2 /var/www/my_domain/web/core/lib/Drupal/Core/Form/FormCache.php(197): Drupal\Core\KeyValueStore\DatabaseStorageExpirable->setWithExpire('form-DsqsvPhU0k...', Array, 21600)
#3 /var/www/my_domain/web/core/lib/Drupal/Core/Form/FormBuilder.php(441): Drupal\Core\Form\FormCache->setCache('form-DsqsvPhU0k...', Array, Object(Drupal\Core\Form\FormState))
#4 /var/www/my_domain/web/core/lib/Drupal/Core/Form/FormBuilder.php(419): Drupal\Core\Form\FormBuilder->setCache('form-DsqsvPhU0k...', Array, Object(Drupal\Core\Form\FormState))
#5 /var/www/my_domain/web/core/lib/Drupal/Core/Form/FormBuilder.php(621): Drupal\Core\Form\FormBuilder->rebuildForm('panels_ipe_bloc...', Object(Drupal\Core\Form\FormState), Array)
#6 /var/www/my_domain/web/core/lib/Drupal/Core/Form/FormBuilder.php(314): Drupal\Core\Form\FormBuilder->processForm('panels_ipe_bloc...', Array, Object(Drupal\Core\Form\FormState))
#7 /var/www/my_domain/web/core/lib/Drupal/Core/Form/FormBuilder.php(212): Drupal\Core\Form\FormBuilder->buildForm('panels_ipe_bloc...', Object(Drupal\Core\Form\FormState))
#8 /var/www/my_domain/web/modules/contrib/panels/panels_ipe/src/Controller/PanelsIPEPageController.php(385): Drupal\Core\Form\FormBuilder->getForm('Drupal\\panels_i...', 'Featured FAQ', Object(Drupal\panels\Plugin\DisplayVariant\PanelsDisplayVariant), 'b9459017-7024-4...')
#9 [internal function]: Drupal\panels_ipe\Controller\PanelsIPEPageController->getBlockPluginForm('page_manager', 'home-panels_var...', 'Featured FAQ', 'b9459017-7024-4...')
#10 /var/www/my_domain/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array(Array, Array)
#11 /var/www/my_domain/web/core/lib/Drupal/Core/Render/Renderer.php(582): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#12 /var/www/my_domain/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(124): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure))
#13 /var/www/my_domain/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array)
#14 [internal function]: Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#15 /var/www/my_domain/web/vendor/symfony/http-kernel/HttpKernel.php(153): call_user_func_array(Object(Closure), Array)
#16 /var/www/my_domain/web/vendor/symfony/http-kernel/HttpKernel.php(68): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1)
#17 /var/www/my_domain/web/core/lib/Drupal/Core/StackMiddleware/Session.php(57): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#18 /var/www/my_domain/web/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(47): Drupal\Core\StackMiddleware\Session->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#19 /var/www/my_domain/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(99): Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#20 /var/www/my_domain/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(78): Drupal\page_cache\StackMiddleware\PageCache->pass(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#21 /var/www/my_domain/web/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(47): Drupal\page_cache\StackMiddleware\PageCache->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#22 /var/www/my_domain/web/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(50): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#23 /var/www/my_domain/web/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#24 /var/www/my_domain/web/core/lib/Drupal/Core/DrupalKernel.php(657): Stack\StackedHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#25 /var/www/my_domain/web/index.php(19): Drupal\Core\DrupalKernel->handle(Object(Symfony\Component\HttpFoundation\Request))
#26 {main}";}

AJAX Error:

AjaxError: 
An AJAX HTTP error occurred.
HTTP Result Code: 500
Debugging information follows.
Path: /admin/panels_ipe/variant/page_manager/home-panels_variant-0/block_plugins/CTA/block/0b850df7-0e57-4b46-acc7-386dd294ff13/form?element_parents=flipper/front/settings/ablecore_style/background/bg_image/image&_wrapper_format=drupal_ajax&ajax_form=1
StatusText: 500 Service unavailable (with message)
ResponseText: The website encountered an unexpected error. Please try again later.
ajax.js:110:32

I was assuming it was related specifically to this issue

a:6:{s:5:"%type";s:9:"Exception";s:8:"@message";s:84:"Serialization of 'Symfony\Component\HttpFoundation\File\UploadedFile' is not allowed

And found someone with a similar issue here

https://stackoverflow.com/questions/45154697/serialization-of-uploadedfile-is-not-allowed

But it was in a non drupal context so I wasn't sure where to go from there. Could the In Place Editor ajax error have to do with the UploadedFile error? And if so how would I resolve this?

1 Answer 1

4

It looks like Drupal is trying to cache a form with an attached UploadedFile object in it.

Is your custom Plugin a Block with a file element in it?

In your blockForm function try:

$form_state->disableCache()

UPDATE 1

Based on @Aaron's feedback I updated buildForm to blockForm above.


Note: Disabling caching for a form does have performance implications.

In general you can disable caching for a form anywhere you create or alter a form. Those functions typically have at least two parameters:

@var array &$form
@var \Drupal\Core\Form\FormStateInterface $form_state
2
  • I'm using a module that extends blockform, so i am able to add background images to any block plugin. So many block plugins have these UploadedFile objects.
    – Aaron
    Feb 16, 2018 at 4:34
  • Thanks for the feedback Aaron. I updated the post based on your experience.
    – ec0g
    Feb 16, 2018 at 17:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.