Project

General

Profile

Actions

Feature #106072

open

Enable Regex in slug field generatorOptions replacements

Added by André Buchmann 13 days ago. Updated 12 days ago.

Status:
Under Review
Priority:
Should have
Category:
Site Handling, Site Sets & Routing
Target version:
-
Start date:
2025-02-03
Due date:
% Done:

0%

Estimated time:
PHP Version:
Tags:
slug
Complexity:
easy
Sprint Focus:

Description

The slug field provides the option to define replacements: https://docs.typo3.org/m/typo3/reference-tca/main/en-us/ColumnsConfig/Type/Slug/Index.html#confval-slug-generatoroptions-replacements

When having to deal with large multilingual sites, there is the typical gender addition on for example job titles: (f/m), (m/w/d), (w/m/d),...
To remove them form slugs, one need to define any of these variations in the replacements array as the replacement method used is: str_replace. Switching to preg_replace would open a lot of new possibilities with regex to define those replacements.
Replacing str_replace with preg_replace is a breaking change!

$replaceConfiguration = $this->configuration['generatorOptions']['replacements'] ?? [];
$pieceOfSlug = str_replace(
    array_keys($replaceConfiguration),
    array_values($replaceConfiguration),
    $pieceOfSlug
);

Comparison of definitions

str_replace preg_replace
            'title with replace' => [
                'Product Cow',
                '/parent-page/product-pig',
                [
                    'generatorOptions' => [
                        'fields' => ['title'],
                        'prefixParentPageSlug' => true,
                        'replacements' => [
                            'Cow' => 'pig',
                        ],
                    ],
                ],
            ],
            'title with slash and replace' => [
                'Product/Cow',
                '/parent-page/productcow',
                [
                    'generatorOptions' => [
                        'fields' => ['title'],
                        'prefixParentPageSlug' => true,
                        'replacements' => [
                            '/' => '',
                        ],
                    ],
                ],
            ],
            'title with slash and replace #2' => [
                'Some Job in city1/city2 (m/w)',
                '/parent-page/some-job-in-city1-city2',
                [
                    'generatorOptions' => [
                        'fields' => ['title'],
                        'prefixParentPageSlug' => true,
                        'replacements' => [
                            '(m/w)' => '',
                            '/' => '-',
                        ],
                    ],
                ],
            ],
            'title with replace' => [
                'Product Cow',
                '/parent-page/product-pig',
                [
                    'generatorOptions' => [
                        'fields' => ['title'],
                        'prefixParentPageSlug' => true,
                        'replacements' => [
                            '/Cow/' => 'pig',
                        ],
                    ],
                ],
            ],
            'title with slash and replace' => [
                'Product/Cow',
                '/parent-page/productcow',
                [
                    'generatorOptions' => [
                        'fields' => ['title'],
                        'prefixParentPageSlug' => true,
                        'replacements' => [
                            '/\//' => '',
                        ],
                    ],
                ],
            ],
            'title with slash and replace #2' => [
                'Some Job in city1/city2 (m/w)',
                '/parent-page/some-job-in-city1-city2',
                [
                    'generatorOptions' => [
                        'fields' => ['title'],
                        'prefixParentPageSlug' => true,
                        'replacements' => [
                            '/\(m\/w\)/' => '',
                            '/\//' => '-',
                        ],
                    ],
                ],
            ],
            'title with slash and replace #3' => [
                'Some Job in city1/city2 (m/w)',
                '/parent-page/some-job-in-city1-city2',
                [
                    'generatorOptions' => [
                        'fields' => ['title'],
                        'prefixParentPageSlug' => true,
                        'replacements' => [
                            '/\(.*\)/' => '',
                            '/\//' => '-',
                        ],
                    ],
                ],
            ],
Actions #1

Updated by André Buchmann 13 days ago

  • Description updated (diff)
Actions #2

Updated by Gerrit Code Review 13 days ago

  • Status changed from New to Under Review

Patch set 1 for branch main of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/88005

Actions #3

Updated by Gerrit Code Review 12 days ago

Patch set 2 for branch main of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/88005

Actions #4

Updated by Gerrit Code Review 12 days ago

Patch set 3 for branch main of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/88005

Actions #5

Updated by Gerrit Code Review 12 days ago

Patch set 4 for branch main of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/88005

Actions #6

Updated by André Buchmann 12 days ago

  • Tracker changed from Task to Feature
  • TYPO3 Version deleted (14)
Actions

Also available in: Atom PDF