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.
Comments
Comment #2
joevagyok CreditAttribution: joevagyok at Arhs for European Commission and European Union Institutions, Agencies and Bodies commentedThe proposed patch.
Comment #3
joevagyok CreditAttribution: joevagyok at Arhs for European Commission and European Union Institutions, Agencies and Bodies commentedComment #4
michaellander CreditAttribution: michaellander at Elevated Third commentedI'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!Comment #5
michaellander CreditAttribution: michaellander at Elevated Third commentedAfter 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.Comment #6
michaellander CreditAttribution: michaellander at Elevated Third commentedI'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.Comment #7
michaellander CreditAttribution: michaellander at Elevated Third commentedFixing one code cleanup item.
Comment #8
michaellander CreditAttribution: michaellander at Elevated Third commentedComment #9
BerdirKernal.
Comment #10
michaellander CreditAttribution: michaellander at Elevated Third commented:D
Comment #11
joevagyok CreditAttribution: joevagyok at Arhs for European Commission and European Union Institutions, Agencies and Bodies commentedNice! Thanks for taking care of the tests, I like your approach! I have tested the patch and it works.
Comment #12
michaellander CreditAttribution: michaellander at Elevated Third commentedThanks! Added in one method name change. Rolling in after test passes.
Comment #14
michaellander CreditAttribution: michaellander at Elevated Third commented