diff --git a/core/lib/Drupal/Core/EventSubscriber/DefaultExceptionHtmlSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/DefaultExceptionHtmlSubscriber.php index e3ec321..fea393c 100644 --- a/core/lib/Drupal/Core/EventSubscriber/DefaultExceptionHtmlSubscriber.php +++ b/core/lib/Drupal/Core/EventSubscriber/DefaultExceptionHtmlSubscriber.php @@ -128,10 +128,10 @@ protected function makeSubrequest(GetResponseForExceptionEvent $event, $url, $st if ($url != $request->getBasePath() . '/' && $url != $current_url) { if ($request->getMethod() === 'POST') { - $sub_request = Request::create($url, 'POST', $this->redirectDestination->getAsArray() + ['_exception_statuscode' => $status_code] + $request->request->all(), $request->cookies->all(), [], $request->server->all()); + $sub_request = Request::create($url, 'POST', ['_exception_location' => $this->redirectDestination->get(), '_exception_statuscode' => $status_code] + $request->request->all(), $request->cookies->all(), [], $request->server->all()); } else { - $sub_request = Request::create($url, 'GET', $request->query->all() + $this->redirectDestination->getAsArray() + ['_exception_statuscode' => $status_code], $request->cookies->all(), [], $request->server->all()); + $sub_request = Request::create($url, 'GET', $request->query->all() + ['_exception_location' => $this->redirectDestination->get(), '_exception_statuscode' => $status_code], $request->cookies->all(), [], $request->server->all()); } try { diff --git a/core/lib/Drupal/Core/Form/FormBuilder.php b/core/lib/Drupal/Core/Form/FormBuilder.php index 618bc98..5483666 100644 --- a/core/lib/Drupal/Core/Form/FormBuilder.php +++ b/core/lib/Drupal/Core/Form/FormBuilder.php @@ -736,13 +736,6 @@ protected function buildFormAction() { // https://www.drupal.org/node/2504709. $parsed = UrlHelper::parse($request_uri); unset($parsed['query'][static::AJAX_FORM_REQUEST], $parsed['query'][MainContentViewSubscriber::WRAPPER_FORMAT]); - - // Ignore the destination if the form is rendered inside a subrequest on a - // 403/404 page. - if ($request->query->has('_exception_statuscode') && $request->query->has('destination')) { - unset($parsed['query']['destination']); - } - return $parsed['path'] . ($parsed['query'] ? ('?' . UrlHelper::buildQuery($parsed['query'])) : ''); } diff --git a/core/modules/user/src/Form/UserLoginForm.php b/core/modules/user/src/Form/UserLoginForm.php index 1c7a342..483d67e 100644 --- a/core/modules/user/src/Form/UserLoginForm.php +++ b/core/modules/user/src/Form/UserLoginForm.php @@ -135,16 +135,17 @@ public function buildForm(array $form, FormStateInterface $form_state) { public function submitForm(array &$form, FormStateInterface $form_state) { $account = $this->userStorage->load($form_state->get('uid')); - // A destination was set, probably on an exception controller, - if (!$this->getRequest()->request->has('destination')) { + // A login form rendered on an error page (e.g. 403) should redirect to the + // original location after a successfull login. + if ($original_location = $this->getRequest()->get('_exception_location')) { + $this->getRequest()->query->set('destination', $original_location); + } + else{ $form_state->setRedirect( 'entity.user.canonical', array('user' => $account->id()) ); } - else { - $this->getRequest()->query->set('destination', $this->getRequest()->request->get('destination')); - } user_login_finalize($account); } diff --git a/core/tests/Drupal/Tests/Core/EventSubscriber/CustomPageExceptionHtmlSubscriberTest.php b/core/tests/Drupal/Tests/Core/EventSubscriber/CustomPageExceptionHtmlSubscriberTest.php index a7efb7e..ab2989c 100644 --- a/core/tests/Drupal/Tests/Core/EventSubscriber/CustomPageExceptionHtmlSubscriberTest.php +++ b/core/tests/Drupal/Tests/Core/EventSubscriber/CustomPageExceptionHtmlSubscriberTest.php @@ -82,8 +82,8 @@ protected function setUp() { $this->redirectDestination = $this->getMock('\Drupal\Core\Routing\RedirectDestinationInterface'); $this->redirectDestination->expects($this->any()) - ->method('getAsArray') - ->willReturn(['destination' => 'test']); + ->method('get') + ->willReturn('test'); $this->customPageSubscriber = new CustomPageExceptionHtmlSubscriber($this->configFactory, $this->aliasManager, $this->kernel, $this->logger, $this->redirectDestination); @@ -146,7 +146,7 @@ public function testHandleWithGetRequest() { $response = $event->getResponse(); $result = $response->getContent() . " " . UrlHelper::buildQuery($request->request->all()); - $this->assertEquals('GET name=druplicon&pass=12345&destination=test&_exception_statuscode=404 ', $result); + $this->assertEquals('GET name=druplicon&pass=12345&_exception_location=test&_exception_statuscode=404 ', $result); } }