Ensure that serializers injectable into Drupal\Core\KeyValueStore are aware of PHP objects

Created on 29 December 2016, almost 8 years ago
Updated 16 February 2024, 10 months ago

Problem/Motivation

The Drupal\Core\KeyValueStore\DatabaseStorage uses a configurable serializer to store PHP objects. This serializer is injected as a service in core. The pre-configured serializer used there Drupal\Component\Serialization\PhpSerialize. But this serializer could be swapped to any serializer that implements Drupal\Component\Serialization\SerializationInterface, for example:

  • Drupal\Component\Serialization\Yaml
  • Drupal\Component\Serialization\Json

These serializers will break PHP objects like in the form_state that gets saved in the key value store.

Proposed resolution

Make serializer customizable for Cache\DatabaseBackend RTBC will introduce a new interface Drupal\Component\Serialization\ObjectAwareSerializationInterface that just extends Drupal\Component\Serialization\SerializationInterface to clearly indicate that implementing Serializers are suitable for PHP Object serialization.

The Drupal\Core\KeyValueStore\DatabaseStorage and Drupal\Core\KeyValueStore\DatabaseStorageExpirable and their factories need to adjusted to expect a serializer that implements that new interface.

Remaining tasks

Write a patch.

User interface changes

None.

API changes

The Drupal\Core\KeyValueStore\DatabaseStorage and Drupal\Core\KeyValueStore\DatabaseStorageExpirable and their factories need to adjusted to expect a serializer that implements that new interface.

Data model changes

None.

🐛 Bug report
Status

Active

Version

11.0 🔥

Component
Database 

Last updated 2 days ago

  • Maintained by
  • 🇳🇱Netherlands @daffie
Created by

🇩🇪Germany mkalkbrenner 🇩🇪

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024