Commit f75945cc authored by Stefan Bürk's avatar Stefan Bürk Committed by Oliver Bartsch
Browse files

[BUGFIX] Ignore prefixParentPageSlug for non-page record in SlugHelper

TCA slug field generator option 'prefixParentPageSlug' has been added
to be used for page records only. Slug generation for non-page records
with pid=0 has been fixed with #94655 which introduced a endless loop
if 'prefixParentPageSlug' is used as slug field generator option for
record tables.

This patch only process 'prefixParentPageSlug' for page records, thus
ignoring it for non-page records and avoiding the endlees loop and as
such prevent segmentation faults or memory_limit fatal errors.

Resolves: #95485
Related: #94655
Releases: master, 11.5, 10.4
Change-Id: I20e1ac68bad6ad9447b03debbedb646495045ac3
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/72168

Reviewed-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
Reviewed-by: Oliver Bartsch's avatarOliver Bartsch <bo@cedev.de>
Tested-by: core-ci's avatarcore-ci <typo3@b13.com>
Tested-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
Tested-by: Oliver Bartsch's avatarOliver Bartsch <bo@cedev.de>
parent e98b794e
......@@ -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);
......
......@@ -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)
);
}
}
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