User registration form broken with unserializable database connection error

Created on 13 December 2023, 7 months ago
Updated 14 December 2023, 7 months ago

Problem/Motivation

Issue 1
After upgrading to entity_legal 4.0.0-alpha2, our our user registration form submission becomes broken with this error:

The website encountered an unexpected error. Please try again later.<br><br><em class="placeholder">LogicException</em>: 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 <em class="placeholder">Drupal\Core\Database\Connection-&gt;__sleep()</em> (line <em class="placeholder">1712</em> of <em class="placeholder">core/lib/Drupal/Core/Database/Connection.php</em>). 
<pre class="backtrace">serialize() (Line: 14)
Drupal\Component\Serialization\PhpSerialize::encode() (Line: 111)
Drupal\Core\KeyValueStore\DatabaseStorageExpirable-&gt;doSetWithExpire() (Line: 127)
Drupal\Core\KeyValueStore\DatabaseStorageExpirable-&gt;setWithExpire() (Line: 193)
Drupal\Core\Form\FormCache-&gt;setCache() (Line: 463)
Drupal\Core\Form\FormBuilder-&gt;setCache() (Line: 441)
Drupal\Core\Form\FormBuilder-&gt;rebuildForm() (Line: 633)
Drupal\Core\Form\FormBuilder-&gt;processForm() (Line: 325)
Drupal\Core\Form\FormBuilder-&gt;buildForm() (Line: 73)
Drupal\Core\Controller\FormController-&gt;getContentResult() (Line: 39)
Drupal\layout_builder\Controller\LayoutBuilderHtmlEntityFormController-&gt;getContentResult()
call_user_func_array() (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber-&gt;Drupal\Core\EventSubscriber\{closure}() (Line: 592)
Drupal\Core\Render\Renderer-&gt;executeInRenderContext() (Line: 121)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber-&gt;wrapControllerExecutionInRenderContext() (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber-&gt;Drupal\Core\EventSubscriber\{closure}() (Line: 181)
Symfony\Component\HttpKernel\HttpKernel-&gt;handleRaw() (Line: 76)
Symfony\Component\HttpKernel\HttpKernel-&gt;handle() (Line: 58)
Drupal\Core\StackMiddleware\Session-&gt;handle() (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle-&gt;handle() (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache-&gt;pass() (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache-&gt;handle() (Line: 53)
Asm89\Stack\Cors-&gt;handle() (Line: 270)
Drupal\shield\ShieldMiddleware-&gt;bypass() (Line: 137)
Drupal\shield\ShieldMiddleware-&gt;handle() (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware-&gt;handle() (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware-&gt;handle() (Line: 51)
Drupal\Core\StackMiddleware\StackedHttpKernel-&gt;handle() (Line: 704)
Drupal\Core\DrupalKernel-&gt;handle() (Line: 19)
</pre>

Issue 2
The second issue is that the admin User creation form (same UserRegistrationForm) now shows the inline Entity Legal entity with acceptance checkbox.

Proposed resolution

Issue 1
My debugging reveals that the plugin ProfileFormEmbedded is also serialised in the form cache. The plugin has recently got new services injected in the latest version and it breaks the serialisation.

We should include the DependencySerializationTrait trait in the base plugin to fix the error.

Issue 2
Version 4-alpha2 refactored the EntityLegalPluginBase::getDocumentsForMethod(). In alpha1, that method returns an empty array for administrators and anonymous users. After being refactored, the method no longer returns so.
In alpha1:

    if (\Drupal::currentUser()->hasPermission('administer entity legal')) {
      return [];
    }

In alpha2:

      if ($this->currentUser->hasPermission('administer entity legal')) {
        $this->documents = [];
      }

I think the refactor incorrectly changed the logic of the method hence the previous behaviour must be restored.

Remaining tasks

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Fixed

Version

4.0

Component

Code

Created by

πŸ‡¦πŸ‡ΊAustralia sonnykt Melbourne, Australia

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

Merge Requests

Comments & Activities

Production build 0.69.0 2024