Skip to content

Commit

Permalink
[TASK] add slug replacements of special chars for "pages" and 'news" …
Browse files Browse the repository at this point in the history
…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
anjeylink authored and dmh committed Mar 14, 2019
1 parent b031e7a commit edff67e
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 5 deletions.
51 changes: 51 additions & 0 deletions Classes/Utility/TcaUtility.php
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
);
}
}
}
6 changes: 5 additions & 1 deletion Configuration/TCA/Overrides/pages.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
defined('TYPO3_MODE') or die();

call_user_func(function () {
$GLOBALS['TCA']['pages']['columns']['tx_themes_icon']['config'] = array (
$GLOBALS['TCA']['pages']['columns']['tx_themes_icon']['config'] = array(
'type' => 'user',
'userFunc' => 'T3kit\themeT3kit\UserFunction\IconFontSelector->renderField',
'cssFile' => 'EXT:theme_t3kit/Resources/Public/IconFonts/style.css',
Expand All @@ -11,4 +11,8 @@
'0' => array('None', '', ''),
),
);

\T3kit\themeT3kit\Utility\TcaUtility::setReplacementsForSlugField(
'pages'
);
});
17 changes: 17 additions & 0 deletions Configuration/TCA/Overrides/tx_news_slug_fields.php
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
);
}
});
6 changes: 2 additions & 4 deletions ext_emconf.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,12 @@
'CGLcompliance_note' => '',
'constraints' => array(
'depends' => array(
'typo3' => '9.5.0-9.5.99'
'typo3' => '9.5.0-9.5.99',
'news' => '7.1.0-7.9.99'
),
'conflicts' => array(
),
'suggests' => array(
),
),
'_md5_values_when_last_written' => 'a:0:{}',
);

?>

0 comments on commit edff67e

Please sign in to comment.