diff --git a/core/lib/Drupal/Core/DrupalKernel.php b/core/lib/Drupal/Core/DrupalKernel.php index 0e679fd..ec0d2a7 100644 --- a/core/lib/Drupal/Core/DrupalKernel.php +++ b/core/lib/Drupal/Core/DrupalKernel.php @@ -685,6 +685,11 @@ protected function initializeContainer($rebuild = FALSE) { $this->containerNeedsDumping = FALSE; $session_manager_started = FALSE; if (isset($this->container)) { + // Save the id of the currently logged in user. + if ($this->container->initialized('current_user')) { + $current_user_id = $this->container->get('current_user')->id(); + } + // If there is a session manager, close and save the session. if ($this->container->initialized('session_manager')) { $session_manager = $this->container->get('session_manager'); @@ -731,6 +736,14 @@ protected function initializeContainer($rebuild = FALSE) { } } } + + if (!empty($current_user_id)) { + $account = $this->container->get('entity.manager')->getStorage('user')->load($current_user_id); + if ($account) { + $this->container->get('current_user')->setAccount($account); + } + } + \Drupal::setContainer($this->container); // If needs dumping flag was set, dump the container.