#95485Slug generation fails for non pages records when prefixParentPageSlug is activated in generatorOptions
Description
Following TCA configuration for non pages records results in a Segmentation Fault because Slughelper::generate() is called infinitively.
This behavior was introduced with https://review.typo3.org/c/Packages/TYPO3.CMS/+/71059
'slug' => [
'config' => [
'type' => 'slug',
'generatorOptions' => [
'prefixParentPageSlug' => true,
],
],
]
The problem is, that for non pages records the $this->tableName is set to something else than pages. As a result the if-clause at the beginning of generate will not become true.
It do not know what the best solution might be. Maybe set $this->tableName = 'pages' after calling $this->resolveParentPageRecord()? But I am not sure whether this would always be true? Please let me know I would like to fix it!
I have created a test to reproduce the problem:
...
namespace TYPO3\CMS\Core\Tests\Unit\DataHandling
...
class SlugHelperTest extends UnitTestCase
{
/**
* @return array
*/
public function generatePrependsSlugsForNonPagesDataProvider(): array
{
return [
'simple title' => [
'Product Name',
'/parent-page/product-name',
[
'generatorOptions' => [
'fields' => ['title'],
'prefixParentPageSlug' => true,
],
],
],
];
}
/**
* @dataProvider generatePrependsSlugsForNonPagesDataProvider
* @param string $input
* @param string $expected
* @test
*/
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)
);
}
}