Version: 2.0.1

Drupal Core: 11.2.8

Problem

When editing views in the Views UI, Drupal throws a fatal error: Exception: Serialization of 'Closure' is not allowed in serialize().
This occurs because Views UI attempts to cache the view configuration, which includes the StringManager service. StringManager has injected
dependencies (ThemeHandlerInterface, StringStorageInterface, CacheBackendInterface) that contain closures through the RequestStack service chain, which
cannot be serialized in PHP.

Proposed Resolution

Add DependencySerializationTrait to the StringManager class. This trait provides proper serialization handling by storing
only service IDs during serialization and re-injecting the actual services during unserialization, preventing the closure serialization error.

Steps to Reproduce

  1. Install String module 2.0.1 on Drupal 11.2.8
  2. Navigate to Structure > Views
  3. Attempt to edit any view (e.g., Content, Media, etc.)
  4. Error occurs:
    Exception: Serialization of 'Closure' is not allowed in serialize() (line 14 of
    core/lib/Drupal/Component/Serialization/PhpSerialize.php)

Comments

mef created an issue. See original summary.

mef’s picture

Issue summary: View changes
mef’s picture

I was able to fix this using this patch. Yet I am unsure if there might be any implications or side effects I am not aware of.
Can somebody have a look and test this?
Thank you

mef’s picture

Issue summary: View changes

  • d34dman committed b7f37380 on 1.x
    fix: #3557845 StringManager causes closure serialization errors in Views...

  • d34dman committed 1a578009 on 2.x
    fix: #3557845 StringManager causes closure serialization errors in Views...