Serialization of Closure is not allowed in serialize

Created on 14 May 2024, 6 months ago
Updated 28 May 2024, 6 months ago

Problem/Motivation

After changes in 📌 Put procedural code into OOP code Active , when using a media library widget in Layout Builder, when clicking the "add media" button there is a fatal error:

The website encountered an unexpected error. Try again later.Exception: Serialization of 'Closure' is not allowed in serialize() (line 15 of core/lib/Drupal/Component/Serialization/PhpSerialize.php). Drupal\Component\Serialization\PhpSerialize::encode(Array) (Line: 112)

This is due to;

\array_unshift($form['#submit'], [$this, 'submitForm']);

in app/modules/contrib/ui_styles/modules/ui_styles_layout_builder/src/HookHandler/FormLayoutBuilderBlockAlter.php, using $this makes the form cache system try to serialize the hook handler and there is a service in it.

Proposed resolution

Either change the code like:

\array_unshift($form['#submit'], ['::submitForm']);

Or try using DependencySerializationTrait

🐛 Bug report
Status

Fixed

Version

1.0

Component

Code

Created by

🇫🇷France Grimreaper France 🇫🇷

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