Skip to content

Commit 7a02493

Browse files
eliashaeusslergeorgringer
authored andcommitted
[BUGFIX] Allow slug recreation if postModifiers are defined
Slug fields currently only support slug recreation if the given generator fields are directly visible in the backend. However, this makes it impossible to recreate slugs even if some postModifiers are defined who can take care of successful slug generation. This commit allows slug recreation if at least one postModifier is defined, even if the defined generator fields are not usable for slug generation. Therefore also EditDocumentController was adjusted to not automatically add slug fields to columnsOnly in case postModifiers are defined for this record. Resolves: #89187 Releases: master, 10.4 Change-Id: Ifd50ec106b5b302cea23d37e470eafae840c8993 Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/66415 Tested-by: TYPO3com <noreply@typo3.com> Tested-by: Georg Ringer <georg.ringer@gmail.com> Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
1 parent 39663f2 commit 7a02493

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

Build/Sources/TypeScript/backend/Resources/Public/TypeScript/FormEngine/Element/SlugElement.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,10 @@ class SlugElement {
9898
}
9999
});
100100
}
101+
}
101102

102-
// Clicking the recreate button makes new slug proposal created from 'title' field
103+
// Clicking the recreate button makes new slug proposal created from 'title' field or any defined postModifiers
104+
if (fieldsToListenOnList.length > 0 || this.hasPostModifiersDefined()) {
103105
$(this.$fullElement).on('click', Selectors.recreateButton, (e: JQueryEventObject): void => {
104106
e.preventDefault();
105107
if (this.$readOnlyField.hasClass('hidden')) {
@@ -218,6 +220,15 @@ class SlugElement {
218220

219221
return availableFields;
220222
}
223+
224+
/**
225+
* Check whether the slug element has post modifiers defined for slug generation
226+
*
227+
* @return boolean
228+
*/
229+
private hasPostModifiersDefined(): boolean {
230+
return Array.isArray(this.options.config.generatorOptions.postModifiers) && this.options.config.generatorOptions.postModifiers.length > 0;
231+
}
221232
}
222233

223234
export = SlugElement;

typo3/sysext/backend/Classes/Controller/EditDocumentController.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -501,8 +501,12 @@ protected function addSlugFieldsToColumnsOnly(array $queryParams): void
501501
if ($this->columnsOnly && $table !== false && isset($GLOBALS['TCA'][$table])) {
502502
$fields = GeneralUtility::trimExplode(',', $this->columnsOnly, true);
503503
foreach ($fields as $field) {
504-
if (isset($GLOBALS['TCA'][$table]['columns'][$field]) && $GLOBALS['TCA'][$table]['columns'][$field]['config']['type'] === 'slug') {
505-
foreach ($GLOBALS['TCA'][$table]['columns'][$field]['config']['generatorOptions']['fields'] as $fields) {
504+
$postModifiers = $GLOBALS['TCA'][$table]['columns'][$field]['config']['generatorOptions']['postModifiers'] ?? [];
505+
if (isset($GLOBALS['TCA'][$table]['columns'][$field])
506+
&& $GLOBALS['TCA'][$table]['columns'][$field]['config']['type'] === 'slug'
507+
&& (!is_array($postModifiers) || $postModifiers === [])
508+
) {
509+
foreach ($GLOBALS['TCA'][$table]['columns'][$field]['config']['generatorOptions']['fields'] ?? [] as $fields) {
506510
$this->columnsOnly .= ',' . (is_array($fields) ? implode(',', $fields) : $fields);
507511
}
508512
}

typo3/sysext/backend/Resources/Public/JavaScript/FormEngine/Element/SlugElement.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)