diff --git a/typo3/sysext/core/Classes/DataHandling/SlugHelper.php b/typo3/sysext/core/Classes/DataHandling/SlugHelper.php index ecb81965fa43f06576d480bca6727a0b4cd12c87..ff7961afb7917e6c85b11114bdb11feb6713ca2a 100644 --- a/typo3/sysext/core/Classes/DataHandling/SlugHelper.php +++ b/typo3/sysext/core/Classes/DataHandling/SlugHelper.php @@ -170,7 +170,7 @@ class SlugHelper return '/'; } $prefix = ''; - if ($this->configuration['generatorOptions']['prefixParentPageSlug'] ?? false) { + if ($this->tableName === 'pages' && ($this->configuration['generatorOptions']['prefixParentPageSlug'] ?? false)) { $languageFieldName = $GLOBALS['TCA'][$this->tableName]['ctrl']['languageField'] ?? null; $languageId = (int)($recordData[$languageFieldName] ?? 0); $parentPageRecord = $this->resolveParentPageRecord($pid, $languageId); diff --git a/typo3/sysext/core/Tests/Unit/DataHandling/SlugHelperTest.php b/typo3/sysext/core/Tests/Unit/DataHandling/SlugHelperTest.php index 87ff88febd098a9f2df0d350c297bd13e735dce6..f25729273d123d84749ac187573636a962eddb70 100644 --- a/typo3/sysext/core/Tests/Unit/DataHandling/SlugHelperTest.php +++ b/typo3/sysext/core/Tests/Unit/DataHandling/SlugHelperTest.php @@ -729,4 +729,50 @@ class SlugHelperTest extends UnitTestCase $subject->generate(['title' => $input['title'], 'uid' => 13], 0) ); } + + public function generatePrependsSlugsForNonPagesDataProvider(): array + { + return [ + 'simple title' => [ + 'Product Name', + 'product-name', + [ + 'generatorOptions' => [ + 'fields' => ['title'], + 'prefixParentPageSlug' => true, + ], + ], + ], + ]; + } + + /** + * @test + * @dataProvider generatePrependsSlugsForNonPagesDataProvider + */ + public function generatePrependsSlugsForNonPages(string $input, string $expected, array $options): void + { + $GLOBALS['dummyTable']['ctrl'] = []; + $parentPage = [ + 'uid' => '0', + 'pid' => null, + ]; + $subject = $this->getAccessibleMock( + SlugHelper::class, + ['resolveParentPageRecord'], + [ + 'another_table', + 'slug', + $options, + ] + ); + $subject->expects(self::any()) + ->method('resolveParentPageRecord') + ->withAnyParameters() + ->willReturn($parentPage); + self::assertEquals( + $expected, + $subject->generate(['title' => $input, 'uid' => 13], 13) + ); + } }