From e076b15bc2d7b1290b88695eea3edce05b7c3f10 Mon Sep 17 00:00:00 2001 From: Iwona Just Date: Wed, 3 Jul 2024 15:39:20 +0200 Subject: [PATCH 1/2] converting from redactor - htmlSupport predefined options --- src/console/controllers/ConvertController.php | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/console/controllers/ConvertController.php b/src/console/controllers/ConvertController.php index 5a4f2be..284ec56 100644 --- a/src/console/controllers/ConvertController.php +++ b/src/console/controllers/ConvertController.php @@ -207,7 +207,7 @@ public function actionRedactor(): int throw new Exception('`manualConfig` contains invalid JSON.'); } $configName = $field['name'] ?? (!empty($field['handle']) ? Inflector::camel2words($field['handle']) : 'Untitled'); - $ckeConfig = $this->generateCkeConfig($configName, $redactorConfig, $ckeConfigs, $fieldSettingsByConfig); + $ckeConfig = $this->generateCkeConfig($configName, $redactorConfig, $ckeConfigs, $fieldSettingsByConfig, $field); $this->stdout(PHP_EOL); } else { $basename = ($field['settings']['redactorConfig'] ?? $field['settings']['configFile'] ?? null) ?: 'Default.json'; @@ -347,6 +347,7 @@ private function generateCkeConfig( array $redactorConfig, array &$ckeConfigs, array &$fieldSettingsByConfig, + ?array $redactorField = null, ): string { // Make sure the name is unique $baseConfigName = $configName; @@ -669,6 +670,22 @@ private function generateCkeConfig( } } + // if we added sourceEditing button, then to align with what Redactor allowed, + // we need add this predefined htmlSupport.allow config + if ($ckeConfig->hasButton('sourceEditing')) { + $htmlSupport = [ + 'attributes' => true, + 'classes' => true, + 'styles' => true, + ]; + + if ($redactorField !== null && $redactorField['settings']['removeInlineStyles']) { + unset($htmlSupport['styles']); + } + + $ckeConfig->options['htmlSupport']['allow'][] = $htmlSupport; + } + // redactor-link-styles if (!empty($fullRedactorConfig['linkClasses'])) { foreach ($fullRedactorConfig['linkClasses'] as $linkClass) { From eebc9a206083ed30b4aedd3e8f8618353ce80e97 Mon Sep 17 00:00:00 2001 From: brandonkelly Date: Thu, 15 Aug 2024 02:48:17 -0400 Subject: [PATCH 2/2] Release note --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d71cf80..f76fcf0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## Unreleased +- CKEditor configs created via the `ckeditor/convert` command now allow modifying HTML attributes, classes, and styles within the source view, if the Redactor config included the `html` button. ([#264](https://github.com/craftcms/ckeditor/pull/264), [#263](https://github.com/craftcms/ckeditor/issues/263)) - Added `craft\ckeditor\events\ModifyConfigEvent::$toolbar`. ([#233](https://github.com/craftcms/ckeditor/pull/233)) - Fixed a bug where code blocks created by a Redactor field only had `
` tags with no `` tags inside them. ([#258](https://github.com/craftcms/ckeditor/issues/258))