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

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

sonnykt created an issue. See original summary.

sonnykt’s picture

Status: Active » Needs review
sonnykt’s picture

Issue summary: View changes
sonnykt’s picture

Issue summary: View changes

claudiu.cristea made their first commit to this issue’s fork.

claudiu.cristea’s picture

Priority: Major » Critical
Status: Needs review » Reviewed & tested by the community

Great that you caught this. Thank you

I wonder why we don't have test coverage at least for the "Issue 2". But I will merge the fix, as is critical, and will open a followup to add coverage.

Added a comit to solve the PHPStan feedback

claudiu.cristea’s picture

Status: Reviewed & tested by the community » Fixed

Thank you

claudiu.cristea’s picture

Released 4.0.0-alpha3

Status: Fixed » Closed (fixed)

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