Forms using entity builders of RDF Sync cannot be serialized

Created on 2 June 2025, 4 days ago

Problem/Motivation

When forms using entity builders of RDF Sync are rebuilt, the following exception is thrown:

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 1920 of core/lib/Drupal/Core/Database/Connection.php).

serialize(Array) (Line: 14)
Drupal\Component\Serialization\PhpSerialize::encode(Array) (Line: 129)
Drupal\Core\KeyValueStore\DatabaseStorageExpirable->doSetWithExpire('form-4X3mSPzKZT16xLeC6sgYFk1ZpkfEvSTrx8csI-LrLbc', Array, 21600) (Line: 145)
Drupal\Core\KeyValueStore\DatabaseStorageExpirable->setWithExpire('form-4X3mSPzKZT16xLeC6sgYFk1ZpkfEvSTrx8csI-LrLbc', Array, 21600) (Line: 193)
Drupal\Core\Form\FormCache->setCache('form-4X3mSPzKZT16xLeC6sgYFk1ZpkfEvSTrx8csI-LrLbc', Array, Object) (Line: 463)
Drupal\Core\Form\FormBuilder->setCache('form-4X3mSPzKZT16xLeC6sgYFk1ZpkfEvSTrx8csI-LrLbc', Array, Object) (Line: 441)
Drupal\Core\Form\FormBuilder->rebuildForm('node_type_edit_form', Object, Array) (Line: 633)
Drupal\Core\Form\FormBuilder->processForm('node_type_edit_form', Array, Object) (Line: 326)
Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 73)
...

Steps to reproduce

1. Enable RDF sync.
2. Trigger the rebuild of any bundle entity form (or field config edit form).
3. You see the exception.

Easiest way to create a button triggering a rebuild:

  1. Add an extra button to a form:

    $form['actions']['test_rebuild'] = [
        '#type' => 'button',
        '#value' => t('Example rebuild'),
        '#submit' => ['example_submit'],
    ];
    
  2. In the submit function:

    function example_submit(array &$form, FormStateInterface $form_state): void {
      $form_state->setRebuild();
    }
    

Proposed resolution

1. The entity builder of FieldConfigFormAlter can be a static method, no need to add the entire FieldConfigFormAlter object to the altered form.
2. BundleEntityFormAlter could use DependencySerializationTrait. Core gives this advice using the adjective temporary, I think the error I'm reporting is a good reason to convert BundleEntityFormAlter's entity builder to a static method.

Remaining tasks

Decide how to fix the error.

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Active

Version

1.0

Component

Code

Created by

πŸ‡­πŸ‡ΊHungary huzooka Hungary πŸ‡­πŸ‡ΊπŸ‡ͺπŸ‡Ί

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024