Skip to content

Commit

Permalink
Merge pull request #264 from craftcms/bugfix/263-convert-command-html…
Browse files Browse the repository at this point in the history
…Support-config

converting from Redactor - `htmlSupport` predefined options
  • Loading branch information
brandonkelly authored Aug 15, 2024
2 parents 4dda672 + eebc9a2 commit 9d4d8b0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<pre>` tags with no `<code>` tags inside them. ([#258](https://github.com/craftcms/ckeditor/issues/258))

Expand Down
19 changes: 18 additions & 1 deletion src/console/controllers/ConvertController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 9d4d8b0

Please sign in to comment.