After testing the implementation of #2876110: Select a Category of blocks instead of individual blocks when configuring the field issue that has been merged on dev, I encountered the following error:

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 1481 of /var/www/html/build/core/lib/Drupal/Core/Database/Connection.php).

In my use case I have locale enabled, and when I edit the field and select "Category" from the "Selection method" field, the ajax throws this error. This error happens ultimately when Drupal tries to cache the form, it has to serialize the data before..

This is due to the new \Drupal\block_field\Plugin\block_field\BlockFieldSelection\Categories implementation where the StringTranslationTrait is used. By looking into core, this Trait is mostly coupled with the DependencySerializationTrait.
In my patch I have added this Triat and the feature works as expected.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

joevagyok created an issue. See original summary.

joevagyok’s picture

The proposed patch.

joevagyok’s picture

Issue summary: View changes
michaellander’s picture

I'm still unable to replicate the error, however I've seen the error in other embedded plugin forms before. I've updated the patch to cover \Drupal\block_field\Plugin\block_field\BlockFieldSelection\Blocks as well. Would like to do a bit more testing before rolling it in. Thanks!

michaellander’s picture

After testing this further and looking at the details of the StringTranslationTrait, I can see why this is needed. I will get this rolled in shortly.

michaellander’s picture

I've added a test to cover this. I wasn't entirely sure if it's best to use KernelTestBase, but wasn't sure how else to instantiate the plugin.

michaellander’s picture

michaellander’s picture

Berdir’s picture

+++ b/tests/src/Kernal/BlockFieldSelectionTest.php
@@ -0,0 +1,70 @@
+namespace Drupal\Tests\block_field\Kernal;

Kernal.

michaellander’s picture

joevagyok’s picture

Status: Needs review » Reviewed & tested by the community

Nice! Thanks for taking care of the tests, I like your approach! I have tested the patch and it works.

michaellander’s picture

Thanks! Added in one method name change. Rolling in after test passes.

  • michaellander committed 681db84 on 8.x-1.x
    Issue #3045769 by michaellander, joevagyok, Berdir: Serialization error...
michaellander’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.