diff --git a/core/lib/Drupal/Core/Entity/Field/FieldItemBase.php b/core/lib/Drupal/Core/Entity/Field/FieldItemBase.php index d831060..5f83147 100644 --- a/core/lib/Drupal/Core/Entity/Field/FieldItemBase.php +++ b/core/lib/Drupal/Core/Entity/Field/FieldItemBase.php @@ -32,6 +32,43 @@ protected $TypedDataManager; /** + * An array of service IDs keyed by property name used for serialization. + * + * @var array + */ + public $_serviceIds = array(); + + /** + * {@inheritdoc} + */ + public function __sleep() { + $this->_serviceIds = array(); + $vars = get_object_vars($this); + foreach ($vars as $key => $value) { + if (is_object($value) && isset($value->_serviceId)) { + // If a class member was instantiated by the dependency injection + // container, only store its ID so it can be used to get a fresh object + // on unserialization. + $this->_serviceIds += array($key => $value->_serviceId); + unset($vars[$key]); + } + } + + return array_keys($vars); + } + + /** + * {@inheritdoc} + */ + public function __wakeup() { + $container = \Drupal::getContainer(); + foreach ($this->_serviceIds as $key => $service_id) { + $this->$key = $container->get($service_id); + } + unset($this->_serviceIDs); + } + + /** * {@inheritdoc} */ public static function create(array $configuration, $name = NULL, $parent = NULL, ContainerInterface $container) {