diff --git a/core/lib/Drupal/Core/TypedData/TypedData.php b/core/lib/Drupal/Core/TypedData/TypedData.php index 4598141..5c34b04 100644 --- a/core/lib/Drupal/Core/TypedData/TypedData.php +++ b/core/lib/Drupal/Core/TypedData/TypedData.php @@ -18,7 +18,7 @@ * Classes deriving from this base class have to declare $value * or override getValue() or setValue(). */ -abstract class TypedData implements TypedDataInterface, PluginInspectionInterface, ContainerFactoryPluginInterface { +abstract class TypedData implements TypedDataInterface, PluginInspectionInterface, ContainerFactoryPluginInterface, \Serializable { /** * The data definition. @@ -226,4 +226,27 @@ public function getPropertyPath() { public function getParent() { return $this->parent; } + + /** + * {@inheritdoc} + */ + public function serialize() { + $that = clone $this; + // Remove the typedDataManager to reduce the size of the object when + // serialized. + unset($that->typedDataManager); + return serialize(get_object_vars($that)); + } + + /** + * {@inheritdoc} + */ + public function unserialize($serialized) { + $data = unserialize($serialized); + foreach ($data as $key => $value) { + $this->{$key} = $value; + } + $this->typedDataManager = \Drupal::typedData(); + } + }