Skip to content

Commit

Permalink
Merge pull request #31 from portrino/dev-10.0
Browse files Browse the repository at this point in the history
updates redirect handling and fix httpResponseCode
  • Loading branch information
elbebass authored Dec 22, 2021
2 parents 355b48c + be52432 commit a10eb38
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 20 deletions.
28 changes: 9 additions & 19 deletions Classes/Action/Redirect.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function process(array &$facts, Decision &$decision)
return;
}

$this->httpStatus = $this->configuration['httpResponseCode'] ? (int)$this->configuration['httpResponseCode'] : HttpUtility::HTTP_STATUS_301;
$this->httpStatus = $this->configuration['httpResponseCode'] ?? HttpUtility::HTTP_STATUS_301;

// Try to redirect to page (if not set, it will be the current page) on configured language
if ($this->configuration['page'] || isset($this->configuration['sys_language'])) {
Expand All @@ -65,9 +65,7 @@ public function process(array &$facts, Decision &$decision)
}

// Try to redirect by configured URL (and language, if configured)
if ($this->configuration['url'] && $this->configuration['sys_language']) {
$this->redirectToUrl($this->configuration['url']);
} elseif ($this->configuration['url']) {
if ($this->configuration['url']) {
$this->redirectToUrl($this->configuration['url']);
}
}
Expand Down Expand Up @@ -174,7 +172,6 @@ private function shouldRedirect(int $sysLanguageUid): bool

/**
* Redirect to a page
* @throws Exception
*/
private function redirectToPid(int $page, int $language): void
{
Expand All @@ -183,26 +180,19 @@ private function redirectToPid(int $page, int $language): void

$contentObjectRenderer = !empty($GLOBALS['TSFE']->cObj) ? $GLOBALS['TSFE']->cObj : new ContentObjectRenderer($GLOBALS['TSFE']);

if ($page > 0) {
if ($page === $GLOBALS['TSFE']->id) {
$this->logger->info('Target page matches current page. No redirect.');
$page = ($page > 0) ? $page : $GLOBALS['TSFE']->id;

return;
}
if ($language >= 0) {
$urlParameters['L'] = $language;
}

if ($page !== $GLOBALS['TSFE']->id || $language >= 0) {
$url = $contentObjectRenderer->getTypoLink_URL($page, $urlParameters);
$url = $GLOBALS['TSFE']->baseUrlWrap($url);
$url = GeneralUtility::locationHeaderURL($url);
} elseif ($language >= 0) {
$urlParameters['L'] = $language;
$url = $contentObjectRenderer->getTypoLink_URL($GLOBALS['TSFE']->id, $urlParameters);
$url = $GLOBALS['TSFE']->baseUrlWrap($url);
$url = GeneralUtility::locationHeaderURL($url);
} else {
throw new Exception(__CLASS__ . ' the configured redirect page is not an integer');
}

$this->redirectToUrl($url);
$this->redirectToUrl($url);
}
}

private function getAdditionalUrlParams(array &$urlParameters): void
Expand Down
2 changes: 1 addition & 1 deletion Classes/Middleware/LanguageRedirectMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
'cookieLifetime' => isset($locateSetup['cookieLifetime']) ? (int)$locateSetup['cookieLifetime'] : Redirect::COOKIE_LIFETIME,
'dryRun' => isset($locateSetup['dryRun']) ? (bool)$locateSetup['dryRun'] : false,
'overrideParam' => $locateSetup['overrideParam'] ?? Redirect::OVERRIDE_PARAMETER,
'responseCode' => $locateSetup['httpResponseCode'] ?? HttpUtility::HTTP_STATUS_301,
'httpResponseCode' => $locateSetup['httpResponseCode'] ?? HttpUtility::HTTP_STATUS_301,
],
];

Expand Down

0 comments on commit a10eb38

Please sign in to comment.