Skip to content

Commit

Permalink
[BUGFIX] Add CKEditor5 migrator for typo3link.additionalAttributes
Browse files Browse the repository at this point in the history
editor.config.typo3link.additionalAttributes was used in
TYPO3 v11 to enable certian attribute on link tags.
Add a migrator that enables the same effect via the
General HTML Support (GHS) CKEditor5 plugin configuration
`config.htmlSupport`.

Also remove the evaluation of the related but unused global config option
['EXTCONF']['rte_ckeditor']['plugins']['TYPO3Link']['additionalAttributes']
which was added in #78917 (initial CKEditor4 linkbrowser integration)
but was never actually used (which was probably undiscovered due to its
similar name).

Resolves: #102052
Releases: main, 12.4
Change-Id: I2ca5b24890dd71dc5cba3aade22995a843e3dd33
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/81334
Reviewed-by: Benjamin Franzke <ben@bnf.dev>
Tested-by: core-ci <typo3@b13.com>
Tested-by: Benjamin Franzke <ben@bnf.dev>
  • Loading branch information
bnf committed Oct 6, 2023
1 parent 20dd373 commit 42e7ea6
Show file tree
Hide file tree
Showing 5 changed files with 148 additions and 10 deletions.
1 change: 0 additions & 1 deletion Build/Sources/TypeScript/rte_ckeditor/plugin/typo3-link.ts
Expand Up @@ -274,7 +274,6 @@ export class Typo3LinkEditing extends Core.Plugin {
// @todo: Why is this needed? Remove.
(window as any).editor = editor;

// @todo YAML additionalAttributes is not implemented yet
editor.model.schema.extend('$text', { allowAttributes: ['linkTitle', 'linkTarget', 'linkRel', 'linkDataRteError'] });

const ghsDataFilter: DataFilter = editor.plugins.get('DataFilter');
Expand Down
20 changes: 20 additions & 0 deletions typo3/sysext/core/Classes/Configuration/CKEditor5Migrator.php
Expand Up @@ -198,6 +198,7 @@ public function __construct(protected array $configuration)
$this->migrateFormatTagsToHeadings();
$this->migrateStylesSetToStyleDefinitions();
$this->migrateContentsCssToArray();
$this->migrateTypo3LinkAdditionalAttributes();
// configure plugins
$this->handleAlignmentPlugin();
$this->handleWhitespacePlugin();
Expand Down Expand Up @@ -582,6 +583,25 @@ protected function migrateContentsCssToArray(): void
}
}

protected function migrateTypo3LinkAdditionalAttributes(): void
{
if (!isset($this->configuration['editor']['config']['typo3link']['additionalAttributes'])) {
return;
}
$additionalAttributes = $this->configuration['editor']['config']['typo3link']['additionalAttributes'];
unset($this->configuration['editor']['config']['typo3link']['additionalAttributes']);
if ($this->configuration['editor']['config']['typo3link'] === []) {
unset($this->configuration['editor']['config']['typo3link']);
}
if (!is_array($additionalAttributes) || $additionalAttributes === []) {
return;
}
$this->configuration['editor']['config']['htmlSupport']['allow'][] = [
'name' => 'a',
'attributes' => array_values($additionalAttributes),
];
}

protected function handleAlignmentPlugin(): void
{
// Migrate legacy configuration
Expand Down
Expand Up @@ -62,6 +62,7 @@ The following options are not needed anymore in CKEditor 5:
* editor.config.entities_latin
* editor.config.entities
* editor.config.extraAllowedContent (covered via GeneralHTMLSupport plugin)
* :php:`$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['rte_ckeditor']['plugins']['TYPO3Link']['additionalAttributes']`

More migration options can be found here:
https://ckeditor.com/docs/ckeditor5/latest/installation/getting-started/migration-from-ckeditor-4.html
Expand Down
127 changes: 127 additions & 0 deletions typo3/sysext/core/Tests/Unit/Configuration/CKEditor5MigratorTest.php
Expand Up @@ -1036,6 +1036,133 @@ public static function migrationDataProvider(): array
],
],

// typo3link.additionalAttributes
'Migrate typo3link.additionalAttributes to config.htmlSupport' => [
[
'editor' => [
'config' => [
'typo3link' => [
'additionalAttributes' => [
'foo',
'bar',
],
],
],
],
],
[
'editor' => [
'config' => [
'htmlSupport' => [
'allow' => [
[
'name' => 'a',
'attributes' => [
'foo',
'bar',
],
],
],
],
'removePlugins' => [],
'toolbar' => [
'items' => [
'softhyphen',
],
'removeItems' => [],
'shouldNotGroupWhenFull' => true,
],
'alignment' => [
'options' => [
['name' => 'left', 'className' => 'text-start'],
['name' => 'center', 'className' => 'text-center'],
['name' => 'right', 'className' => 'text-end'],
['name' => 'justify', 'className' => 'text-justify'],
],
],
'wordCount' => [
'displayCharacters' => true,
'displayWords' => true,
],
],
],
],
],
'Unset empty typo3link.additionalAttributes' => [
[
'editor' => [
'config' => [
'typo3link' => [
'additionalAttributes' => [],
],
],
],
],
[
'editor' => [
'config' => [
'removePlugins' => [],
'toolbar' => [
'items' => [
'softhyphen',
],
'removeItems' => [],
'shouldNotGroupWhenFull' => true,
],
'alignment' => [
'options' => [
['name' => 'left', 'className' => 'text-start'],
['name' => 'center', 'className' => 'text-center'],
['name' => 'right', 'className' => 'text-end'],
['name' => 'justify', 'className' => 'text-justify'],
],
],
'wordCount' => [
'displayCharacters' => true,
'displayWords' => true,
],
],
],
],
],
'Unset invalid values in typo3link.additionalAttributes' => [
[
'editor' => [
'config' => [
'typo3link' => [
'additionalAttributes' => 'invalid string value',
],
],
],
],
[
'editor' => [
'config' => [
'removePlugins' => [],
'toolbar' => [
'items' => [
'softhyphen',
],
'removeItems' => [],
'shouldNotGroupWhenFull' => true,
],
'alignment' => [
'options' => [
['name' => 'left', 'className' => 'text-start'],
['name' => 'center', 'className' => 'text-center'],
['name' => 'right', 'className' => 'text-end'],
['name' => 'justify', 'className' => 'text-justify'],
],
],
'wordCount' => [
'displayCharacters' => true,
'displayWords' => true,
],
],
],
],
],

// Plugin Alignment Handling
'Remove Alignment Plugin' => [
[
Expand Down
Expand Up @@ -46,7 +46,6 @@ class BrowseLinksController extends AbstractLinkBrowserController
protected array $classesAnchorDefaultTarget = [];
protected array $classesAnchorJSOptions = [];
protected string $defaultLinkTarget = '';
protected array $additionalAttributes = [];
protected string $siteUrl = '';

public function __construct(
Expand Down Expand Up @@ -243,14 +242,6 @@ protected function renderLinkAttributeFields(ViewInterface $view): string
? $this->classesAnchorDefaultTarget[$this->displayedLinkHandlerId]
: ($this->buttonConfig[$this->displayedLinkHandlerId]['properties']['target']['default'] ?? $this->buttonConfig['properties']['target']['default'] ?? '');

// todo: find new name for this option
// Initializing additional attributes
if ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['rte_ckeditor']['plugins']['TYPO3Link']['additionalAttributes'] ?? false) {
$addAttributes = GeneralUtility::trimExplode(',', $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['rte_ckeditor']['plugins']['TYPO3Link']['additionalAttributes'], true);
foreach ($addAttributes as $attribute) {
$this->additionalAttributes[$attribute] = $this->linkAttributeValues[$attribute] ?? '';
}
}
return parent::renderLinkAttributeFields($view);
}

Expand Down

0 comments on commit 42e7ea6

Please sign in to comment.