Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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

- Statically-rendered CKEditor fields are now shown in read-only mode. ([#466](https://github.com/craftcms/ckeditor/pull/466))
- Fixed a bug where `reversed` attributes were being removed from `<ol>` elements by HTML Purifier. ([#463](https://github.com/craftcms/ckeditor/issues/463))

## 4.10.1 - 2025-08-18
Expand Down
47 changes: 32 additions & 15 deletions src/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -980,7 +980,30 @@ protected function createFieldData(string $content, ?int $siteId): HtmlFieldData
/**
* @inheritdoc
*/
protected function inputHtml(mixed $value, ?ElementInterface $element, $inline): string
protected function inputHtml(mixed $value, ?ElementInterface $element, bool $inline): string
{
return $this->_inputHtml($value, $element, false);
}

/**
* @inheritdoc
*/
public function getStaticHtml(mixed $value, ?ElementInterface $element): string
{
return $this->_inputHtml($value, $element, true);
}

/**
* Return the HTML for the CKEditor field.
*
* @param mixed $value
* @param ElementInterface $element
* @param bool $static
* @return string
* @throws InvalidConfigException
* @throws \Throwable
*/
private function _inputHtml(mixed $value, ?ElementInterface $element, bool $static): string
{
$view = Craft::$app->getView();
$view->registerAssetBundle(CkeditorAsset::class);
Expand Down Expand Up @@ -1199,7 +1222,15 @@ protected function inputHtml(mixed $value, ?ElementInterface $element, $inline):
}
config.removePlugins.push(...extraRemovePlugins);
}

instance = CKEditor5.craftcms.create($idJs, config);

if (Boolean($static)) {
instance.then((editor) => {
editor.enableReadOnlyMode($idJs);
});

}
})(jQuery)
JS,
View::POS_END,
Expand Down Expand Up @@ -1233,20 +1264,6 @@ protected function inputHtml(mixed $value, ?ElementInterface $element, $inline):
]);
}

/**
* @inheritdoc
*/
public function getStaticHtml(mixed $value, ElementInterface $element): string
{
Craft::$app->getView()->registerAssetBundle(CkeditorAsset::class);

return Html::tag(
'div',
$this->prepValueForInput($value, $element, true) ?: '&nbsp;',
['class' => 'noteditable']
);
}

/**
* @inheritdoc
*/
Expand Down
2 changes: 1 addition & 1 deletion src/web/assets/ckeditor/dist/ckeditor5-craftcms.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/web/assets/ckeditor/dist/ckeditor5-craftcms.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/web/assets/ckeditor/dist/css/ckeditor5-craftcms.css

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

Loading
Loading