Skip to content

Commit

Permalink
[BUGFIX] Allow slug recreation if postModifiers are defined
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
eliashaeussler authored and georgringer committed Nov 4, 2020
1 parent 39663f2 commit 7a02493
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
Expand Up @@ -98,8 +98,10 @@ class SlugElement {
}
});
}
}

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

return availableFields;
}

/**
* Check whether the slug element has post modifiers defined for slug generation
*
* @return boolean
*/
private hasPostModifiersDefined(): boolean {
return Array.isArray(this.options.config.generatorOptions.postModifiers) && this.options.config.generatorOptions.postModifiers.length > 0;
}
}

export = SlugElement;
Expand Up @@ -501,8 +501,12 @@ protected function addSlugFieldsToColumnsOnly(array $queryParams): void
if ($this->columnsOnly && $table !== false && isset($GLOBALS['TCA'][$table])) {
$fields = GeneralUtility::trimExplode(',', $this->columnsOnly, true);
foreach ($fields as $field) {
if (isset($GLOBALS['TCA'][$table]['columns'][$field]) && $GLOBALS['TCA'][$table]['columns'][$field]['config']['type'] === 'slug') {
foreach ($GLOBALS['TCA'][$table]['columns'][$field]['config']['generatorOptions']['fields'] as $fields) {
$postModifiers = $GLOBALS['TCA'][$table]['columns'][$field]['config']['generatorOptions']['postModifiers'] ?? [];
if (isset($GLOBALS['TCA'][$table]['columns'][$field])
&& $GLOBALS['TCA'][$table]['columns'][$field]['config']['type'] === 'slug'
&& (!is_array($postModifiers) || $postModifiers === [])
) {
foreach ($GLOBALS['TCA'][$table]['columns'][$field]['config']['generatorOptions']['fields'] ?? [] as $fields) {
$this->columnsOnly .= ',' . (is_array($fields) ? implode(',', $fields) : $fields);
}
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7a02493

Please sign in to comment.