Project

General

Profile

Feature #106072

Updated by André Buchmann 7 days ago

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!* 

 <pre><code class="php"> 
 $replaceConfiguration = $this->configuration['generatorOptions']['replacements'] ?? []; 
 $pieceOfSlug = str_replace( 
     array_keys($replaceConfiguration), 
     array_values($replaceConfiguration), 
     $pieceOfSlug 
 ); 
 </code></pre> 


 Comparison of definitions 

 |_.str_replace|_.preg_replace| 
 | <pre>              '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)' => '', 
                             '/' => '-', 
                         ], 
                     ], 
                 ], 
             ],</pre> | <pre>              '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' => [ 
                             '/\(.*\)/' => '', 
                             '/\//' => '-', 
                         ], 
                     ], 
                 ], 
             ],</pre> | 

Back