Skip to content

Commit edff67e

Browse files
anjeylinkdmh
authored andcommitted
[TASK] add slug replacements of special chars for "pages" and 'news" tables (#494)
* [BUGFIX] use valid path for category label * [TASK] add possibility to set additional replacements for pages slug field (special chars) * [TASK] add news as dependency * [TASK] add replacements for news tables
1 parent b031e7a commit edff67e

File tree

4 files changed

+75
-5
lines changed

4 files changed

+75
-5
lines changed

Classes/Utility/TcaUtility.php

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace T3kit\themeT3kit\Utility;
5+
6+
/**
7+
* Class TcaUtility
8+
* @package T3kit\themeT3kit\Utility
9+
*/
10+
class TcaUtility
11+
{
12+
/**
13+
* Default slug replacements
14+
*
15+
* @var array
16+
*/
17+
protected static $slugReplacements = [
18+
'ä' => 'a',
19+
'å' => 'a',
20+
'ö' => 'o',
21+
'Å' => 'a',
22+
'Ä' => 'a',
23+
'Ö' => 'o',
24+
'ø' => 'o',
25+
'Ø' => 'o'
26+
];
27+
28+
/**
29+
* Set replacements for TCA slug field
30+
*
31+
* @param string $tableName TCA table name
32+
* @param string $slugFieldName Slug field name in TCA columns
33+
* @param array $additionalReplacements Additional replacements for default slug replacements
34+
*/
35+
public static function setReplacementsForSlugField(
36+
string $tableName,
37+
string $slugFieldName = 'slug',
38+
array $additionalReplacements = []
39+
): void {
40+
if (isset($GLOBALS['TCA'][$tableName]['columns'][$slugFieldName]['config']['generatorOptions'])
41+
&& is_array($GLOBALS['TCA'][$tableName]['columns'][$slugFieldName]['config']['generatorOptions'])
42+
) {
43+
$replacements = array_merge(static::$slugReplacements, $additionalReplacements);
44+
$generatorOptions = &$GLOBALS['TCA'][$tableName]['columns'][$slugFieldName]['config']['generatorOptions'];
45+
$generatorOptions['replacements'] = array_merge(
46+
$generatorOptions['replacements'] ?? [],
47+
$replacements
48+
);
49+
}
50+
}
51+
}

Configuration/TCA/Overrides/pages.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
defined('TYPO3_MODE') or die();
33

44
call_user_func(function () {
5-
$GLOBALS['TCA']['pages']['columns']['tx_themes_icon']['config'] = array (
5+
$GLOBALS['TCA']['pages']['columns']['tx_themes_icon']['config'] = array(
66
'type' => 'user',
77
'userFunc' => 'T3kit\themeT3kit\UserFunction\IconFontSelector->renderField',
88
'cssFile' => 'EXT:theme_t3kit/Resources/Public/IconFonts/style.css',
@@ -11,4 +11,8 @@
1111
'0' => array('None', '', ''),
1212
),
1313
);
14+
15+
\T3kit\themeT3kit\Utility\TcaUtility::setReplacementsForSlugField(
16+
'pages'
17+
);
1418
});
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
defined('TYPO3_MODE') || die('Access denied.');
3+
4+
call_user_func(function () {
5+
$tableToField = [
6+
'sys_category' => 'slug',
7+
'tx_news_domain_model_tag' => 'slug',
8+
'tx_news_domain_model_news' => 'path_segment',
9+
];
10+
11+
foreach ($tableToField as $table => $field) {
12+
\T3kit\themeT3kit\Utility\TcaUtility::setReplacementsForSlugField(
13+
$table,
14+
$field
15+
);
16+
}
17+
});

ext_emconf.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,12 @@
3434
'CGLcompliance_note' => '',
3535
'constraints' => array(
3636
'depends' => array(
37-
'typo3' => '9.5.0-9.5.99'
37+
'typo3' => '9.5.0-9.5.99',
38+
'news' => '7.1.0-7.9.99'
3839
),
3940
'conflicts' => array(
4041
),
4142
'suggests' => array(
4243
),
4344
),
44-
'_md5_values_when_last_written' => 'a:0:{}',
4545
);
46-
47-
?>

0 commit comments

Comments
 (0)