-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[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
- Loading branch information
Showing
4 changed files
with
75 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace T3kit\themeT3kit\Utility; | ||
|
||
/** | ||
* Class TcaUtility | ||
* @package T3kit\themeT3kit\Utility | ||
*/ | ||
class TcaUtility | ||
{ | ||
/** | ||
* Default slug replacements | ||
* | ||
* @var array | ||
*/ | ||
protected static $slugReplacements = [ | ||
'ä' => 'a', | ||
'å' => 'a', | ||
'ö' => 'o', | ||
'Å' => 'a', | ||
'Ä' => 'a', | ||
'Ö' => 'o', | ||
'ø' => 'o', | ||
'Ø' => 'o' | ||
]; | ||
|
||
/** | ||
* Set replacements for TCA slug field | ||
* | ||
* @param string $tableName TCA table name | ||
* @param string $slugFieldName Slug field name in TCA columns | ||
* @param array $additionalReplacements Additional replacements for default slug replacements | ||
*/ | ||
public static function setReplacementsForSlugField( | ||
string $tableName, | ||
string $slugFieldName = 'slug', | ||
array $additionalReplacements = [] | ||
): void { | ||
if (isset($GLOBALS['TCA'][$tableName]['columns'][$slugFieldName]['config']['generatorOptions']) | ||
&& is_array($GLOBALS['TCA'][$tableName]['columns'][$slugFieldName]['config']['generatorOptions']) | ||
) { | ||
$replacements = array_merge(static::$slugReplacements, $additionalReplacements); | ||
$generatorOptions = &$GLOBALS['TCA'][$tableName]['columns'][$slugFieldName]['config']['generatorOptions']; | ||
$generatorOptions['replacements'] = array_merge( | ||
$generatorOptions['replacements'] ?? [], | ||
$replacements | ||
); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
defined('TYPO3_MODE') || die('Access denied.'); | ||
|
||
call_user_func(function () { | ||
$tableToField = [ | ||
'sys_category' => 'slug', | ||
'tx_news_domain_model_tag' => 'slug', | ||
'tx_news_domain_model_news' => 'path_segment', | ||
]; | ||
|
||
foreach ($tableToField as $table => $field) { | ||
\T3kit\themeT3kit\Utility\TcaUtility::setReplacementsForSlugField( | ||
$table, | ||
$field | ||
); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters