diff --git a/CHANGELOG.md b/CHANGELOG.md index fa81219..4c76ae0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Release Notes for CKEditor for Craft CMS +## Unreleased + +- Fixed a bug where `@import` statements within custom styles weren’t working. ([#538](https://github.com/craftcms/ckeditor/pull/538)) + ## 5.2.0 - 2026-03-12 - It’s now possible to drag-and-drop images into fields with the “Nested entries” image mode, if the “Add nested content” button is present, but not “Insert image”. ([#524](https://github.com/craftcms/ckeditor/issues/524)) diff --git a/src/Field.php b/src/Field.php index 1d516d5..1297e89 100644 --- a/src/Field.php +++ b/src/Field.php @@ -1573,7 +1573,20 @@ private function _inputHtml(mixed $value, ?ElementInterface $element, bool $stat } if ($this->css) { - $view->registerCss("#{$view->namespaceInputId($inputId)} { $this->css }"); + $css = $this->css; + $imports = []; + preg_match_all('/@import .+;?/m', $css, $importMatches); + for ($i = 0; $i < count($importMatches[0]); $i++) { + $imports[] = $importMatches[0][$i]; + $css = str_replace($importMatches[0][$i], '', $css); + } + if (!empty($imports)) { + $view->registerCss(implode("\n", $imports)); + } + $css = trim($css); + if ($css !== '') { + $view->registerCss("#{$view->namespaceInputId($inputId)} { $css }"); + } } return Html::tag('div', $html, [