diff --git a/core/modules/node/src/EventSubscriber/NodeTranslationExceptionSubscriber.php b/core/modules/node/src/EventSubscriber/NodeTranslationExceptionSubscriber.php index 39a2540169..85b7023b23 100644 --- a/core/modules/node/src/EventSubscriber/NodeTranslationExceptionSubscriber.php +++ b/core/modules/node/src/EventSubscriber/NodeTranslationExceptionSubscriber.php @@ -91,21 +91,22 @@ public function onException(GetResponseForExceptionEvent $event) { return; } - // If the node_translation_redirect state is not set, we don't need to check - // for a redirection. - if (!$this->state->get('node_translation_redirect')) { - return; - } + $previous_exception = $exception->getPrevious(); + if ($previous_exception instanceof ParamNotConvertedException) { + $route_name = $previous_exception->getRouteName(); + $parameters = $previous_exception->getRawParameters(); + if ($route_name === 'entity.node.canonical' && isset($parameters['node'])) { + + // If the node_translation_redirect state is not set, we don't need to check + // for a redirection. + if (!$this->state->get('node_translation_redirect')) { + return; + } - $previousException = $exception->getPrevious(); - if ($previousException instanceof ParamNotConvertedException) { - $routeName = $previousException->getRouteName(); - $parameters = $previousException->getRawParameters(); - if ($routeName === 'entity.node.canonical' && isset($parameters['node'])) { - $oldNid = $parameters['node']; + $old_nid = $parameters['node']; $collection = $this->keyValue->get('node_translation_redirect'); - if ($oldNid && $collection->has($oldNid)) { - list($nid, $langcode) = $collection->get($oldNid); + if ($old_nid && $value = $collection->get($old_nid)) { + list($nid, $langcode) = $value; $language = $this->languageManager->getLanguage($langcode); $url = $this->urlGenerator->generateFromRoute('entity.node.canonical', ['node' => $nid], ['language' => $language]); $response = new RedirectResponse($url, 301);