Commit 8877fab7 authored by Stefan Galinski's avatar Stefan Galinski

[BUGFIX] Fix dependency to sg_account

parent adf921d1
......@@ -32,7 +32,6 @@ use TYPO3\CMS\Core\Controller\ErrorPageController;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Error\Http\PageNotFoundException;
use TYPO3\CMS\Core\Http\Request;
use TYPO3\CMS\Core\Http\Uri;
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\HttpUtility;
......@@ -81,18 +80,20 @@ class RoutingService {
$request = $GLOBALS['TYPO3_REQUEST'];
$loginUrl = $this->getLoginPageUrl($request);
$isPageAccessFailureFrontendGroup = \array_key_exists('fe_group', $pageAccessFailureReasons);
$isSgAccountLoaded = ExtensionManagementUtility::isLoaded('sg_account');
$isKeyNumeric = isset($pageAccessFailureReasons['fe_group']) ?
\is_numeric(key($pageAccessFailureReasons['fe_group'])) : FALSE;
if ($isPageAccessFailureFrontendGroup && $isSgAccountLoaded && $loginUrl !== '' && $isKeyNumeric) {
// This can only be changed to a Response based approach, if TYPO3 lets us somehow return a
// RedirectReponse object
@\ob_end_clean();
\header('HTTP/1.1 302 PagenotfoundHandler Redirect');
\header('Location: ' . GeneralUtility::locationHeaderUrl($loginUrl));
exit;
if ($isPageAccessFailureFrontendGroup && $isSgAccountLoaded) {
$loginUrl = $this->getLoginPageUrl($request);
if ($loginUrl !== '' && $isKeyNumeric) {
// This can only be changed to a Response based approach, if TYPO3 lets us somehow return a
// RedirectResponse object
@\ob_end_clean();
\header('HTTP/1.1 302 PagenotfoundHandler Redirect');
\header('Location: ' . GeneralUtility::locationHeaderUrl($loginUrl));
exit;
}
}
$rootUid = $request->getAttribute('site')->getRootPageId();
......@@ -165,7 +166,9 @@ class RoutingService {
}
try {
$response = $errorController->pageNotFoundAction($GLOBALS['TYPO3_REQUEST'], 'Page Not Found', $parameters['pageAccessFailureReasons']);
$response = $errorController->pageNotFoundAction(
$GLOBALS['TYPO3_REQUEST'], 'Page Not Found', $parameters['pageAccessFailureReasons']
);
} catch (PageNotFoundException $exception) {
// this can happen if e.g. the wanted error page can't be fetched.
......@@ -212,7 +215,7 @@ class RoutingService {
}
if (
\is_numeric($route['destination_url']) ||
\substr($route['destination_url'], 0, 5) === 't3://'
strpos($route['destination_url'], 't3://') === 0
) {
$report = [
'error' => 0
......@@ -271,6 +274,12 @@ class RoutingService {
* @throws \UnexpectedValueException
*/
private function getLoginPageUrl(Request $request): string {
if (!ExtensionManagementUtility::isLoaded('sg_account')) {
return '';
}
/** @noinspection PhpUndefinedClassInspection */
/** @noinspection PhpUndefinedNamespaceInspection */
$sgAccountConfiguration = \SGalinski\SgAccount\Utility\ExtensionUtility::getExtensionConfiguration();
$loginRedirectUrl = \trim($sgAccountConfiguration['loginRedirectUrl']);
if ($loginRedirectUrl === '') {
......@@ -279,10 +288,12 @@ class RoutingService {
$GLOBALS['TSFE']->sys_page = GeneralUtility::makeInstance(PageRepository::class);
$contentObjectRenderer = GeneralUtility::makeInstance(ContentObjectRenderer::class, $GLOBALS['TSFE']);
$redirectUri = $contentObjectRenderer->typoLink_URL([
'parameter' => $loginRedirectUrl,
'additionalParams' => '&' . $request->getUri()->getQuery()
]);
$redirectUri = $contentObjectRenderer->typoLink_URL(
[
'parameter' => $loginRedirectUrl,
'additionalParams' => '&' . $request->getUri()->getQuery()
]
);
return $redirectUri ?? $loginRedirectUrl;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment