Commit 9c60241e authored by Stefan Galinski's avatar Stefan Galinski

Merge branch 'bugfix_ParentPageRedirect' into 'master'

[BUGFIX] Fix the default configuration to call the parent page on empty configuration

See merge request !9
parents 5f16f1f7 64a1f16e
......@@ -108,56 +108,86 @@ class RoutingService {
->where(
$queryBuilder->expr()->eq('pid', $queryBuilder->createNamedParameter($rootUid, \PDO::PARAM_INT))
)->execute()->fetch();
if ($handling && $handling['function'] !== '') {
if ($handling) {
$configurationFound = TRUE;
$function = $handling['function'];
$isFunctionStartsWithT3Prefix = (\strpos($function, self::URL_WIZARD_ID) === 0);
$evaluationFunctionThatItsNotStartedWithNumbers = ((string) (int) $function);
if (
(
($evaluationFunctionThatItsNotStartedWithNumbers === $function) &&
(int) $function
) ||
$isFunctionStartsWithT3Prefix
) {
$GLOBALS['TSFE']->sys_page = GeneralUtility::makeInstance(PageRepository::class);
$contentObjectRenderer = GeneralUtility::makeInstance(
ContentObjectRenderer::class, $GLOBALS['TSFE']
);
$parameters = [
'parameter' => $function
];
$languageId = GeneralUtility::makeInstance(Context::class)->getPropertyFromAspect(
'language', 'id'
$GLOBALS['TSFE']->sys_page = GeneralUtility::makeInstance(PageRepository::class);
$contentObjectRenderer = GeneralUtility::makeInstance(
ContentObjectRenderer::class, $GLOBALS['TSFE']
);
if ($function === '') {
// empty function means redirect to parent page
$pageId = $request->getAttribute('routing')->getPageId();
$pageQueryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable(
'pages'
);
if ($languageId) {
$queryBuilder = GeneralUtility::makeInstance(
ConnectionPool::class
)->getQueryBuilderForTable('sys_language');
$languageCount = $queryBuilder->select('uid')
->from('sys_language')
->where(
$queryBuilder->expr()->eq(
'uid', $queryBuilder->createNamedParameter($languageId, \PDO::PARAM_INT)
$currentPageResult = $pageQueryBuilder->select('parent.uid')
->from('pages', 'parent')
->leftJoin('parent', 'pages', 'current', 'current.pid=parent.uid')
->where(
$pageQueryBuilder->expr()->eq('current.uid', $pageQueryBuilder->createNamedParameter($pageId, \PDO::PARAM_INT))
)->execute()->fetch();
if (isset($currentPageResult['uid'])) {
// we do a real redirect to ensure the page we redirect to exists
// this is made possible by restarting the whole routing process with the new page
$function = $contentObjectRenderer->typoLink_URL(['parameter' => $currentPageResult['uid'], 'forceAbsoluteUrl' => TRUE]);
@\ob_end_clean();
\header($handling['header']);
\header('Location: ' . GeneralUtility::locationHeaderUrl($function));
exit;
} else {
// no page to redirect to found, set configurationFound to FALSE to kick in the default 404 handling
$configurationFound = FALSE;
}
} else {
// a Page ID, file or 'true' has been set as redirect target
$isFunctionStartsWithT3Prefix = (\strpos($function, self::URL_WIZARD_ID) === 0);
$evaluationFunctionThatItsNotStartedWithNumbers = ((string) (int) $function);
if (
(
($evaluationFunctionThatItsNotStartedWithNumbers === $function) &&
(int) $function
) ||
$isFunctionStartsWithT3Prefix
) {
// Handle a given page id
$parameters = [
'parameter' => $function
];
$languageId = GeneralUtility::makeInstance(Context::class)->getPropertyFromAspect(
'language', 'id'
);
if ($languageId) {
$queryBuilder = GeneralUtility::makeInstance(
ConnectionPool::class
)->getQueryBuilderForTable('sys_language');
$languageCount = $queryBuilder->select('uid')
->from('sys_language')
->where(
$queryBuilder->expr()->eq(
'uid', $queryBuilder->createNamedParameter($languageId, \PDO::PARAM_INT)
)
)
)
->setMaxResults(1)->execute()->rowCount();
if ($languageCount > 0) {
$parameters['additionalParams'] = '&L=' . $languageId;
} else {
$parameters['additionalParams'] = '&L=0';
->setMaxResults(1)->execute()->rowCount();
if ($languageCount > 0) {
$parameters['additionalParams'] = '&L=' . $languageId;
} else {
$parameters['additionalParams'] = '&L=0';
}
}
}
$function = $contentObjectRenderer->typoLink_URL($parameters);
$function = $contentObjectRenderer->typoLink_URL($parameters);
}
}
// here we either have 'true' or an actual file/URL as error page
$GLOBALS['TYPO3_CONF_VARS']['FE']['pageNotFound_handling'] = $function;
$GLOBALS['TYPO3_CONF_VARS']['FE']['pageNotFound_handling_statheader'] = $handling['header'];
}
}
if (!$configurationFound) {
// if no configuration has been found, use the default pageNotFoundHandling
$GLOBALS['TYPO3_CONF_VARS']['FE']['pageNotFound_handling'] =
$GLOBALS['TYPO3_CONF_VARS']['FE']['tx_routes_pageNotFound_handling_original'];
}
......
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