Problem/Motivation
Since #3574230: Use a weak reference for EntityBase::typedData, EntityBase::$typedData has WeakReference, which PHP cannot serialize. EntityBase::__sleep() sets to NULL before serialization.
The __sleep() magic methods from FieldConfigBase and FieldStorageConfig build their property list with get_object_vars($this) and never call parent::__sleep(), so typedData is kept.
After getTypedData() has been called, serializing a FieldConfig, BaseFieldOverride or FieldStorageConfig throws:
Exception: Serialization of 'WeakReference' is not allowed
I don't think core itself can trigger this but contrib could by calling getTypedData() on a field config entity, then caching or serializing will fail.
Steps to reproduce
$storage = \Drupal\field\Entity\FieldStorageConfig::loadByName("node", "body");
$storage->getTypedData();
serialize($storage);
Proposed resolution
Build the property list from parent::__sleep() instead of get_object_vars($this), as View::__sleep() already does.
Remaining tasks
- Review.
- Coordinate with #3548971, which replaces __sleep() with __serialize().
Issue fork drupal-3644277
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
Comment #2
pcambraComment #3
pcambraComment #5
pcambraComment #6
pcambra