Commit afa6a7ca authored by Paul Ilea's avatar Paul Ilea

[FEATURE] Add language selection for page-id redirects

parent 938deaa7
......@@ -93,7 +93,9 @@ class RedirectResolver implements MiddlewareInterface {
$GLOBALS['TYPO3_CONF_VARS']['FE']['tx_routes_executed'][$rootUid] = TRUE;
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('tx_sgroutes_domain_model_route');
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable(
'tx_sgroutes_domain_model_route'
);
$queryBuilder->getRestrictions()->removeAll()->add(GeneralUtility::makeInstance(DeletedRestriction::class));
$resultArray = $queryBuilder->select(
'uid',
......@@ -102,9 +104,11 @@ class RedirectResolver implements MiddlewareInterface {
'source_url',
'source_url_case_sensitive',
'destination_url',
'destination_language',
'redirect_url_parameters',
'redirect_code',
'description')
'description'
)
->from('tx_sgroutes_domain_model_route')
->where(
$queryBuilder->expr()->eq('pid', $queryBuilder->createNamedParameter($rootUid, \PDO::PARAM_INT))
......@@ -155,15 +159,17 @@ class RedirectResolver implements MiddlewareInterface {
}
if (
(
(bool)$redirect['source_url_case_sensitive'] &&
(bool) $redirect['source_url_case_sensitive'] &&
(string) $uri === (string) $sourceUrl
) ||
(
!(bool)$redirect['source_url_case_sensitive'] &&
!(bool) $redirect['source_url_case_sensitive'] &&
\mb_strtolower($uri) === \mb_strtolower($sourceUrl)
)
) {
$redirectUri = $this->getRedirectUrl($redirect['destination_url'], $requestParameters);
$redirectUri = $this->getRedirectUrl(
$redirect['destination_url'], $requestParameters, $redirect['destination_language']
);
if ($redirectUri === '') {
// the page either does not exist or isn't accessible, drop out
return GeneralUtility::makeInstance(ErrorController::class)->pageNotFoundAction(
......@@ -190,20 +196,24 @@ class RedirectResolver implements MiddlewareInterface {
*
* @param $destinationUrl
* @param $requestParameters
* @param int $destinationLanguageUid
* @return string
*/
protected function getRedirectUrl($destinationUrl, $requestParameters): string {
protected function getRedirectUrl($destinationUrl, $requestParameters, $destinationLanguageUid = 0): string {
if (\strpos($destinationUrl, self::URL_WIZARD_ID) === 0) {
$destinationUrl = (int) \substr($destinationUrl, 14);
$requestParameters[] = 'L=' . $destinationLanguageUid;
}
if (\is_numeric($destinationUrl)) {
$GLOBALS['TSFE']->sys_page = GeneralUtility::makeInstance(PageRepository::class);
$contentObjectRenderer = GeneralUtility::makeInstance(ContentObjectRenderer::class, $GLOBALS['TSFE']);
$redirectUri = $contentObjectRenderer->typoLink_URL([
'parameter' => $destinationUrl,
'additionalParams' => '&' . \implode('&', $requestParameters)
]);
$redirectUri = $contentObjectRenderer->typoLink_URL(
[
'parameter' => $destinationUrl,
'additionalParams' => '&' . \implode('&', $requestParameters)
]
);
}
return $redirectUri ?? $destinationUrl;
}
......@@ -218,13 +228,17 @@ class RedirectResolver implements MiddlewareInterface {
* @throws \InvalidArgumentException
*/
private function logRedirect($routeRow, $requestUri, $redirectUri, $start, $end): void {
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('tx_sgroutes_domain_model_log');
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable(
'tx_sgroutes_domain_model_log'
);
$queryBuilder->getRestrictions()->removeAll();
$categories = $queryBuilder->select('c.title')
->from('tx_sgroutes_domain_model_category', 'c')
->innerJoin('c', 'tx_sgroutes_domain_model_route_category', 'mm', 'c.uid = mm.uid_foreign')
->where(
$queryBuilder->expr()->eq('mm.uid_local', $queryBuilder->createNamedParameter($routeRow['uid'], \PDO::PARAM_INT))
$queryBuilder->expr()->eq(
'mm.uid_local', $queryBuilder->createNamedParameter($routeRow['uid'], \PDO::PARAM_INT)
)
)
->orderBy('mm.sorting')
->execute()->fetchAll();
......
......@@ -2,9 +2,9 @@
if (\SGalinski\SgRoutes\Service\LicensingService::checkKey()) {
$showFields = 'use_regular_expression, regular_expression_info, --palette--;LLL:EXT:sg_routes/Resources/Private/Language/locallang_db.xlf:tx_sgroutes_domain_model_route.palettes.source_url;source_url, destination_url, redirect_url_parameters, redirect_code, description, categories';
$showFields = 'use_regular_expression, regular_expression_info, --palette--;LLL:EXT:sg_routes/Resources/Private/Language/locallang_db.xlf:tx_sgroutes_domain_model_route.palettes.source_url;source_url, --palette--;LLL:EXT:sg_routes/Resources/Private/Language/locallang_db.xlf:tx_sgroutes_domain_model_route.palettes.destination_url;destination_url, redirect_url_parameters, redirect_code, description, categories';
} else {
$showFields = '--palette--;LLL:EXT:sg_routes/Resources/Private/Language/locallang_db.xlf:tx_sgroutes_domain_model_route.palettes.source_url;source_url, destination_url, redirect_url_parameters, redirect_code, description, categories';
$showFields = '--palette--;LLL:EXT:sg_routes/Resources/Private/Language/locallang_db.xlf:tx_sgroutes_domain_model_route.palettes.source_url;source_url, --palette--;LLL:EXT:sg_routes/Resources/Private/Language/locallang_db.xlf:tx_sgroutes_domain_model_route.palettes.destination_url;destination_url, redirect_url_parameters, redirect_code, description, categories';
}
return [
......@@ -42,6 +42,9 @@ return [
'palettes' => [
'source_url' => [
'showitem' => 'source_url,source_url_case_sensitive'
],
'destination_url' => [
'showitem' => 'destination_url,destination_language'
]
],
'columns' => [
......@@ -123,6 +126,16 @@ return [
'softref' => 'typolink'
],
],
'destination_language' => [
'exclude' => 0,
'label' => 'LLL:EXT:sg_routes/Resources/Private/Language/locallang_db.xlf:tx_sgroutes_domain_model_route.destination_language',
'config' => [
'type' => 'select',
'renderType' => 'selectSingle',
'size' => 1,
'special' => 'languages'
],
],
'redirect_url_parameters' => [
'exclude' => 0,
'label' => 'LLL:EXT:sg_routes/Resources/Private/Language/locallang_db.xlf:tx_sgroutes_domain_model_route.redirect_url_parameters',
......
......@@ -93,9 +93,13 @@
<source>Description</source>
<target>Beschreibung</target>
</trans-unit>
<trans-unit id="tx_sgroutes_domain_model_route.destination_language">
<source>Language (Only for Page Id Destination)</source>
<target>Sprache (Nur für Seiten-ID-Ziel)</target>
</trans-unit>
<trans-unit id="tx_sgroutes_domain_model_route.destination_url" approved="yes">
<source>Destination URL (Examples: "/contact-us/" , "/contact-us/$1") or Page Id</source>
<target>Ziel-URL (Beispiele: "/kontaktiere-uns/" , "/kontaktiere-uns/$1") oder Seiten Id</target>
<target>Ziel-URL (Beispiele: "/kontaktiere-uns/" , "/kontaktiere-uns/$1") oder Seiten-ID</target>
</trans-unit>
<trans-unit id="tx_sgroutes_domain_model_route.permanently" approved="yes">
<source>301 (Permanent Redirect)</source>
......@@ -125,6 +129,10 @@
<source>Regular Expression Tester</source>
<target>Reguläre Ausdrücke Tester</target>
</trans-unit>
<trans-unit id="tx_sgroutes_domain_model_route.palettes.destination_url">
<source>Destination URL</source>
<target>Ziel-URL</target>
</trans-unit>
<trans-unit id="tx_sgroutes_domain_model_route.palettes.source_url">
<source>Source URL</source>
<target>Quell-URL</target>
......
......@@ -72,6 +72,9 @@
<trans-unit id="tx_sgroutes_domain_model_route.description">
<source>Description</source>
</trans-unit>
<trans-unit id="tx_sgroutes_domain_model_route.destination_language">
<source>Language (Only for Page Id Destination)</source>
</trans-unit>
<trans-unit id="tx_sgroutes_domain_model_route.destination_url">
<source>Destination URL (Examples: "/contact-us/" , "/contact-us/$1") or Page Id</source>
</trans-unit>
......@@ -96,6 +99,9 @@
<trans-unit id="tx_sgroutes_domain_model_route.regular_expression_info_tester">
<source>Regular Expression Tester</source>
</trans-unit>
<trans-unit id="tx_sgroutes_domain_model_route.palettes.destination_url">
<source>Destination URL</source>
</trans-unit>
<trans-unit id="tx_sgroutes_domain_model_route.palettes.source_url">
<source>Source URL</source>
</trans-unit>
......
......@@ -9,6 +9,7 @@ CREATE TABLE tx_sgroutes_domain_model_route (
source_url varchar(255) DEFAULT '' NOT NULL,
source_url_case_sensitive tinyint(4) unsigned DEFAULT '0' NOT NULL,
destination_url varchar(255) DEFAULT '' NOT NULL,
destination_language int(11) unsigned DEFAULT '0' NOT NULL,
redirect_url_parameters tinyint(4) unsigned DEFAULT '0' NOT NULL,
redirect_code varchar(255) DEFAULT '301' NOT NULL,
description text NOT NULL,
......
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