Classes/Service/SlugService.php | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/Classes/Service/SlugService.php b/Classes/Service/SlugService.php index 9fd25d8..79167b4 100644 --- a/Classes/Service/SlugService.php +++ b/Classes/Service/SlugService.php @@ -133,7 +133,8 @@ class SlugService implements LoggerAwareInterface if ($this->autoUpdateSlugs || $this->autoCreateRedirects) { $this->createCorrelationIds($pageId, $correlationId); if ($this->autoCreateRedirects) { - $this->createRedirect($currentSlug, $defaultPageId, (int)$currentPageRecord['sys_language_uid'], (int)$pageId); + $suffix = $this->getUrlSuffixForPageType(); + $this->createRedirect($currentSlug . $suffix, $defaultPageId, (int)$currentPageRecord['sys_language_uid'], (int)$pageId); } if ($this->autoUpdateSlugs) { $this->checkSubPages($currentPageRecord, $currentSlug, $newSlug); @@ -210,6 +211,7 @@ class SlugService implements LoggerAwareInterface protected function checkSubPages(array $currentPageRecord, string $oldSlugOfParentPage, string $newSlugOfParentPage): void { + $suffix = $this->getUrlSuffixForPageType(); $languageUid = (int)$currentPageRecord['sys_language_uid']; // resolveSubPages needs the page id of the default language $pageId = $languageUid === 0 ? (int)$currentPageRecord['uid'] : (int)$currentPageRecord['l10n_parent']; @@ -218,7 +220,7 @@ class SlugService implements LoggerAwareInterface $newSlug = $this->updateSlug($subPageRecord, $oldSlugOfParentPage, $newSlugOfParentPage); if ($newSlug !== null && $this->autoCreateRedirects) { $subPageId = (int)$subPageRecord['sys_language_uid'] === 0 ? (int)$subPageRecord['uid'] : (int)$subPageRecord['l10n_parent']; - $this->createRedirect($subPageRecord['slug'], $subPageId, $languageUid, $pageId); + $this->createRedirect($subPageRecord['slug'] . $suffix, $subPageId, $languageUid, $pageId); } } } @@ -357,6 +359,28 @@ class SlugService implements LoggerAwareInterface return $queryBuilder; } + protected function getUrlSuffixForPageType(int $typeNum = 0): string + { + $suffix = ''; + $siteConfiguration = $this->site->getConfiguration(); + $routeEnhancers = $siteConfiguration['routeEnhancers']; + if (is_string($routeEnhancers['PageTypeSuffix']['type']) === true && $routeEnhancers['PageTypeSuffix']['type'] === 'PageType') { + if (is_string($routeEnhancers['PageTypeSuffix']['default']) === true) { + $suffix = $routeEnhancers['PageTypeSuffix']['default']; + } + + if (is_array($routeEnhancers['PageTypeSuffix']['map']) === true && $key = array_search($typeNum, $routeEnhancers['PageTypeSuffix']['map'])) { + $suffix = $key; + } + + if($suffix !== '' && $suffix[0] !== '.') { + $suffix .= '/' . $suffix; + } + } + + return $suffix; + } + protected function enabledHook(): void { $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processDatamapClass']['redirects'] =