Bug #95692
closedSlugHelper doesn't respect TCA settings
100%
Description
First the problem occurs even in TYPO3 10 and 9, too.
The PHP-Version is set to 8, because with this php-version the problem errors instead of ignores the problem. But the main probelm is somewhere else.
Description¶
When using the Core\DataHandling\SlugHelper inside any other context except of Backend dataset editing, values given by the database will not mapped correct to the generate method, which occurs an error inside TYPO3v11 with PHP 8.0.
Working not with PHP8.0 but with 7.4, no error will occur, but handling is different to the backend.
Example¶
'path_segment' => [
'label' => 'LLL:EXT:template/Resources/Private/Language/locallang_tca.xlf:event.path_segment',
'config' => [
'type' => 'slug',
'generatorOptions' => [
'fields' => [
'title',
'uid',
],
'fieldSeparator' => '-',
'prefixParentPageSlug' => true,
'replacements' => [
'/' => '',
],
],
'fallbackCharacter' => '-',
'eval' => 'uniqueInSite',
'default' => '',
]
],
will generate correct slug like /title-of-my-event-12 with php 7.4 both in Backend and Console command or frontend generated.
The same configuration in v11 with php 8.0 will generate correct slug from backend, but will throw error from frontend or console command.
[ TypeError ] str_replace(): Argument #3 ($subject) must be of type array|string, int given
stack trace:
#0 () typo3/sysext/core/Classes/DataHandling/SlugHelper.php:203 #1 str_replace() typo3/sysext/core/Classes/DataHandling/SlugHelper.php:203 #2 TYPO3\CMS\Core\DataHandling\SlugHelper->generate() packages/template/Classes/Service/SlugService.php:109 #3 Calien\Template\Service\SlugService->updateSlug() packages/template/Classes/Command/UpdateSlugsCommand.php:74 #4 Calien\Template\Command\UpdateSlugsCommand->execute() vendor/symfony/console/Command/Command.php:299 #5 Symfony\Component\Console\Command\Command->run() vendor/symfony/console/Application.php:978 #6 Symfony\Component\Console\Application->doRunCommand() vendor/helhum/typo3-console/Classes/Console/Mvc/Cli/Symfony/Application.php:189 #7 Helhum\Typo3Console\Mvc\Cli\Symfony\Application->doRunCommand() vendor/symfony/console/Application.php:295 #8 Symfony\Component\Console\Application->doRun() vendor/symfony/console/Application.php:167 #9 Symfony\Component\Console\Application->run() vendor/helhum/typo3-console/Classes/Console/Core/Kernel.php:114 #10 Helhum\Typo3Console\Core\Kernel->handle() vendor/helhum/typo3-console/Scripts/typo3-console.php:31 #11 {closure}() vendor/helhum/typo3-console/Scripts/typo3-console.php:33 #12 require() vendor/helhum/typo3-console/typo3cms:3
Same error appears in frontend.
Additionally, if using datetime/date/ other related fields like mm-relations will occur error, too, because the generate mostly only gets the plain database row for creating the slug but not the TCA defined values like titles or date-time formatted strings.
Unfortunately, the methods calling these values are mostly protected, so you have to copy them into own classes.
Solution¶
Let SlugHelper respect the TCA configuration and render the fields given like in TCA. This problemm occurs since introducing the Slugs inside TYPO3 9.5, I guess, but until PHP 8.0 nobody took effect of this.
Other example¶
'start' => [
'label' => 'LLL:EXT:template/Resources/Private/Language/locallang_tca.xlf:event.start',
'config' => [
'type' => 'input',
'eval' => 'datetime',
'renderType' => 'inputDateTime'
]
],
'path_segment' => [
'label' => 'LLL:EXT:template/Resources/Private/Language/locallang_tca.xlf:event.path_segment',
'config' => [
'type' => 'slug',
'generatorOptions' => [
'fields' => [
'title',
'start',
],
'fieldSeparator' => '-',
'prefixParentPageSlug' => true,
'replacements' => [
'/' => '',
],
],
'fallbackCharacter' => '-',
'eval' => 'uniqueInSite',
'default' => '',
]
],
create table tx_template_domain_model_event
(
title varchar(255) default '' not null,
location int(11) default '0' not null,
max_participants int(11) default '0' not null,
registrations int(11) default '0' not null,
start int(11) default '0' not null,
end int(11) default '0' not null,
description text,
cwa_qr_code text,
youth_service int(2) unsigned default '0' not null,
children_service int(2) unsigned default '0' not null,
path_segment varchar(255) default '' not null,
registration_start int(11) default '0' not null
);
Generates from backend sth like /my-event-title-1200-2021-10-12
Generates from console/Frontend with php 7.4 sth like /my-event-title-1634032800
which isn't consistent, but accessing the TCA settings is impossible.
The same configuration occurs error in PHP 8.0 because of the unix timestamp saved as integer inside database and Doctrine will return as integer.
Updated by Gerrit Code Review over 2 years ago
- Status changed from New to Under Review
Patch set 1 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/71878
Updated by Gerrit Code Review over 2 years ago
Patch set 2 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/71878
Updated by Gerrit Code Review over 2 years ago
Patch set 1 for branch 10.4 of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/71854
Updated by Markus Klein over 2 years ago
- Status changed from Under Review to Resolved
- % Done changed from 0 to 100
Applied in changeset 4db1b8065d89df17a3e7fe40b5aa1efdba448c8c.