diff --git a/core/lib/Drupal/Core/DependencyInjection/DependencySerializationTrait.php b/core/lib/Drupal/Core/DependencyInjection/DependencySerializationTrait.php index cb6a27d04c4a..9de7e71b9412 100644 --- a/core/lib/Drupal/Core/DependencyInjection/DependencySerializationTrait.php +++ b/core/lib/Drupal/Core/DependencyInjection/DependencySerializationTrait.php @@ -49,9 +49,10 @@ public function __sleep() { * {@inheritdoc} */ public function __wakeup() { - $container = \Drupal::getContainer(); - foreach ($this->_serviceIds as $key => $service_id) { - $this->$key = $container->get($service_id); + if ($container = \Drupal::getContainer()) { + foreach ($this->_serviceIds as $key => $service_id) { + $this->$key = $container->get($service_id); + } } $this->_serviceIds = array(); }