From ae071ad7f6e133a1c41cd30f97b506c7d6d0e31c Mon Sep 17 00:00:00 2001 From: i-just Date: Mon, 16 Mar 2026 10:31:49 +0100 Subject: [PATCH 1/4] register import css statements without the namespace --- src/Field.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Field.php b/src/Field.php index 1d516d5..740e6e2 100644 --- a/src/Field.php +++ b/src/Field.php @@ -1573,7 +1573,17 @@ private function _inputHtml(mixed $value, ?ElementInterface $element, bool $stat } if ($this->css) { - $view->registerCss("#{$view->namespaceInputId($inputId)} { $this->css }"); + preg_match_all('/@import .+;/', $this->css, $importStatements); + if (count($importStatements[0]) > 0) { + foreach ($importStatements[0] as $importStatement) { + str_replace($importStatement, '', $this->css); + $view->registerCss("$importStatement"); + } + } + $this->css = trim($this->css); + if (!empty($this->css)) { + $view->registerCss("#{$view->namespaceInputId($inputId)} { $this->css }"); + } } return Html::tag('div', $html, [ From 2329ba305e07a15a922dd358830f4e41862bcae4 Mon Sep 17 00:00:00 2001 From: i-just Date: Tue, 17 Mar 2026 16:10:43 +0100 Subject: [PATCH 2/4] tweaks --- src/Field.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Field.php b/src/Field.php index 740e6e2..c23ad97 100644 --- a/src/Field.php +++ b/src/Field.php @@ -1576,8 +1576,8 @@ private function _inputHtml(mixed $value, ?ElementInterface $element, bool $stat preg_match_all('/@import .+;/', $this->css, $importStatements); if (count($importStatements[0]) > 0) { foreach ($importStatements[0] as $importStatement) { - str_replace($importStatement, '', $this->css); - $view->registerCss("$importStatement"); + $this->css = str_replace($importStatement, '', $this->css); + $view->registerCss($importStatement); } } $this->css = trim($this->css); From a930ad28b6c99a88181308e631c272c30d16334a Mon Sep 17 00:00:00 2001 From: brandonkelly Date: Tue, 17 Mar 2026 14:50:11 -0700 Subject: [PATCH 3/4] Cleanup --- src/Field.php | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/Field.php b/src/Field.php index c23ad97..1297e89 100644 --- a/src/Field.php +++ b/src/Field.php @@ -1573,16 +1573,19 @@ private function _inputHtml(mixed $value, ?ElementInterface $element, bool $stat } if ($this->css) { - preg_match_all('/@import .+;/', $this->css, $importStatements); - if (count($importStatements[0]) > 0) { - foreach ($importStatements[0] as $importStatement) { - $this->css = str_replace($importStatement, '', $this->css); - $view->registerCss($importStatement); - } + $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)); } - $this->css = trim($this->css); - if (!empty($this->css)) { - $view->registerCss("#{$view->namespaceInputId($inputId)} { $this->css }"); + $css = trim($css); + if ($css !== '') { + $view->registerCss("#{$view->namespaceInputId($inputId)} { $css }"); } } From 1992fbb0d247e43c04097e14b3b236853656295a Mon Sep 17 00:00:00 2001 From: brandonkelly Date: Tue, 17 Mar 2026 14:51:45 -0700 Subject: [PATCH 4/4] Release note --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) 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))