When using this module in combination with entity_embed it completely breaks the widget. When clicking the media selection the AJAX does not run and the console logs:

Statustext: 500 Service unavailable (with message)
Antworttext: Auf der Website ist ein unvorhergesehener Fehler aufgetreten. Bitte versuchen Sie es später nochmal.LogicException: The database connection is not serializable. This probably means you are serializing an object that has an indirect reference to the database connection. Adjust your code so that is not necessary. Alternatively, look at DependencySerializationTrait as a temporary solution. in Drupal\Core\Database\Connection->__sleep() (line 1472 of core/lib/Drupal/Core/Database/Connection.php). serialize(Array) (Line: 14)
Drupal\Component\Serialization\PhpSerialize::encode(Array) (Line: 81)
Drupal\Core\KeyValueStore\DatabaseStorageExpirable->setWithExpire('form-JtyNbWCOv5i9ZL-UOUXltp5-zDkZc1KaAcUilBJWIVc', Array, 21600) (Line: 197)
Drupal\Core\Form\FormCache->setCache('form-JtyNbWCOv5i9ZL-UOUXltp5-zDkZc1KaAcUilBJWIVc', Array, Object) (Line: 441)
Drupal\Core\Form\FormBuilder->setCache('form-JtyNbWCOv5i9ZL-UOUXltp5-zDkZc1KaAcUilBJWIVc', Array, Object) (Line: 419)
Drupal\Core\Form\FormBuilder->rebuildForm('node_page_edit_form', Object, Array) (Line: 621)
Drupal\Core\Form\FormBuilder->processForm('node_page_edit_form', Array, Object) (Line: 314)
Drupal\Core\Form\FormBuilder->buildForm('node_page_edit_form', Object) (Line: 74)
Drupal\Core\Controller\FormController->getContentResult(Object, Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 576)
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}()
call_user_func_array(Object, Array) (Line: 153)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 68)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 57)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 99)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 78)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 50)
Drupal\ban\BanMiddleware->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 50)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 657)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
ajax.js:110:32

I think the reason may be related to: #2893029: EntityType objects cannot be reliably serialized without DependencySerializationTrait
I tried the patch from #2893029: EntityType objects cannot be reliably serialized without DependencySerializationTrait but it does not solve the problem with background_image. After uninstalling background_image without any other changes everything works fine.

background_image uses StringTranslationTrait in:

  • src/BackgroundImageManager.php:use Drupal\Core\StringTranslation\StringTranslationTrait;
  • src/BackgroundImageManager.php: use StringTranslationTrait;
  • src/Entity/BackgroundImage.php:use Drupal\Core\StringTranslation\StringTranslationTrait;
  • src/Entity/BackgroundImage.php: use StringTranslationTrait;
  • src/Form/BackgroundImageForm.php:use Drupal\Core\StringTranslation\StringTranslationTrait;
  • src/Form/BackgroundImageForm.php: use StringTranslationTrait;

Comments

Anybody created an issue. See original summary.

anybody’s picture

Issue summary: View changes
anybody’s picture

Issue summary: View changes
anybody’s picture

Priority: Normal » Major

I tried to fix it by adding

use DependencySerializationTrait;

in class BackgroundImageManager

but that didn't solve the problem. Same problem as before. Caches cleared etc.

markhalliwell’s picture

Priority: Major » Normal
Status: Active » Postponed (maintainer needs more info)

As I stated in my blog post, Media API integration is planned but not something that is currently supported. Nor was it even built with it in mind really. There will, undoubtedly, be issues with that... but how many of the errors are byproducts of Media API not yet being fully stable? I'm not sure I want or can spend much time on this topic until it has been moved into core and become a stable module.

anybody’s picture

Hi Mark,

thanks a lot for your quick feedback!
I absolutely understand if you decide to wait for media to become part of core.

But just to make that clear: We didn't use media as part of background_image. So we didn't change the upload field or something like that. We're just using media_entity and entity_embed in our nodes. That's broken after enabling background_image.

So it would be great if you could find a simple solution to make them compatible and perhaps have a look at that issue, but no problem if you don't have the time for it.

Thank you very much.

markhalliwell’s picture

Status: Postponed (maintainer needs more info) » Closed (outdated)

I don't think this is an issue any longer as there hasn't been any further discussion on this. If I'm wrong, some clearer direction towards the issue may help. Also, there's #3103713: Add Entity Browser Integration which might be semi-related... maybe not.