Skip to content

Commit 9353b58

Browse files
[BUGFIX] Support custom identifiers for PageType enhancer
1 parent e4f5db4 commit 9353b58

File tree

2 files changed

+55
-3
lines changed

2 files changed

+55
-3
lines changed

Classes/Sitemap/Provider/PageTypeProvider.php

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@
3434
*/
3535
final class PageTypeProvider implements Provider
3636
{
37+
/**
38+
* @see https://github.com/TYPO3/typo3/blob/v12.4.0/typo3/sysext/core/Configuration/DefaultConfiguration.php#L118
39+
*/
40+
private const EXPECTED_ENHANCER_TYPE = 'PageType';
41+
3742
/**
3843
* @see https://github.com/TYPO3/typo3/blob/v12.4.0/typo3/sysext/seo/Configuration/TypoScript/XmlSitemap/setup.typoscript#L3
3944
*/
@@ -48,10 +53,11 @@ public function get(
4853
return [];
4954
}
5055

51-
$pageTypeMap = $site->getConfiguration()['routeEnhancers']['PageTypeSuffix']['map'] ?? null;
56+
// Look up page type map
57+
$pageTypeMap = $this->fetchPageTypeMapFromSiteConfiguration($site);
5258

5359
// Early return if no page type map is configured
54-
if (!\is_array($pageTypeMap) || !\in_array(self::EXPECTED_PAGE_TYPE, $pageTypeMap, true)) {
60+
if (!\in_array(self::EXPECTED_PAGE_TYPE, $pageTypeMap, true)) {
5561
return [];
5662
}
5763

@@ -71,4 +77,29 @@ public static function getPriority(): int
7177
{
7278
return 300;
7379
}
80+
81+
/**
82+
* @return array<string, int>
83+
*/
84+
private function fetchPageTypeMapFromSiteConfiguration(Core\Site\Entity\Site $site): array
85+
{
86+
$routeEnhancers = $site->getConfiguration()['routeEnhancers'] ?? [];
87+
$pageTypeMap = null;
88+
89+
foreach ($routeEnhancers as $routeEnhancer) {
90+
$type = $routeEnhancer['type'] ?? null;
91+
92+
if ($type === self::EXPECTED_ENHANCER_TYPE) {
93+
$pageTypeMap = $routeEnhancer['map'] ?? null;
94+
95+
break;
96+
}
97+
}
98+
99+
if (!\is_array($pageTypeMap)) {
100+
return [];
101+
}
102+
103+
return $pageTypeMap;
104+
}
74105
}

Tests/Functional/Sitemap/Provider/PageTypeProviderTest.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function getReturnsEmptyArrayIfSeoExtensionIsNotLoaded(): void
6060
}
6161

6262
#[Framework\Attributes\Test]
63-
public function getReturnsEmptyArrayIfPageTypeIsNotConfigured(): void
63+
public function getReturnsEmptyArrayIfNoRouteEnhancersAreConfigured(): void
6464
{
6565
$this->packageManager->loadedExtensions = ['seo'];
6666

@@ -69,6 +69,27 @@ public function getReturnsEmptyArrayIfPageTypeIsNotConfigured(): void
6969
self::assertSame([], $this->subject->get($site));
7070
}
7171

72+
#[Framework\Attributes\Test]
73+
public function getReturnsEmptyArrayIfPageTypeIsNotConfigured(): void
74+
{
75+
$this->packageManager->loadedExtensions = ['seo'];
76+
77+
$site = new Core\Site\Entity\Site('foo', 1, [
78+
'base' => 'https://www.example.com/',
79+
'routeEnhancers' => [
80+
'Foo' => [
81+
'type' => 'Simple',
82+
'routePath' => '/foo/{foo_id}',
83+
'_arguments' => [
84+
'foo_id' => 'foo/id',
85+
],
86+
],
87+
],
88+
]);
89+
90+
self::assertSame([], $this->subject->get($site));
91+
}
92+
7293
#[Framework\Attributes\Test]
7394
public function getReturnsSitemapWithPageTypeFromSite(): void
7495
{

0 commit comments

Comments
 (0)