I added my theme css using the following in the *.info.yml:

ckeditor_stylesheets:
  - css/style.css

While updating the css/style.css I found that my changes wasn't reflecting into the WYSIWYG editor. Watching at the html head of the editor iframe I found that my css file was include as follow:

<link type="text/css" rel="stylesheet" href="/my_project/docroot/themes/unepmap/css/style.css">

That is, the above isn't included with any cache busting as any of the other css includes!?...

Now, not sure what is supposed to do CKEDITOR.timestamp included in #2679903: CKEditor uses separate cache-busting query string from Drupal's but it doesn't seems to cover the the above...

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

drikc created an issue. See original summary.

drikc’s picture

Status: Active » Needs review
FileSize
717 bytes

The attached patch add a cache busting into ckeditor iframe css includes.

Wim Leers’s picture

Title: ckeditor_stylesheets cache busting » ckeditor_stylesheets cache busting: use system.css_js_query_string
Status: Needs review » Needs work

Hah, nice edge case that you found! Thanks for reporting, and thanks even more for the initial patch, which definitely looks like it's on the right path!

If you can address the following feedback, this will be ready :)

+++ b/core/modules/ckeditor/src/Plugin/Editor/CKEditor.php
@@ -423,6 +423,9 @@ public function buildContentsCssJSSetting(Editor $editor) {
+      return $item . '?cb=' . \Drupal::state()->get('system.css_js_query_string') ?: '0';

Rather than calling \Drupal::state(), this should inject the state service.

And rather than making it ?cb=…, it should be using the same approach as \Drupal\Core\Asset\JsCollectionRenderer::render().

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

fenstrat’s picture

Status: Needs work » Needs review
FileSize
2.84 KB
2.97 KB

Attached addresses the feedback from #3.

Wim Leers’s picture

Status: Needs review » Needs work

👍 — great step forward! Thank you!

But this is not yet addressed:
And rather than making it <code>?cb=…, it should be using the same approach as \Drupal\Core\Asset\JsCollectionRenderer::render().

That function does this:

          $query_string = $js_asset['version'] == -1 ? $default_query_string : 'v=' . $js_asset['version'];
          $query_string_separator = (strpos($js_asset['data'], '?') !== FALSE) ? '&' : '?';

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

joshuautley’s picture

I spent 3 hours yesterday and around three hours today trying everything I could think of including switching to developer mode over at Cloudflare.

I just not found this thread by searching for "ckeditor_stylesheets" < Sometimes it is just knowing what to search for.

I seriously thought I went crazy after drinking an energy drink. I was like... wait that was working then now, what? Then I went on my six hour trouble shooting binge repeatedly hitting my head again the brick wall until a single brick finally fell out letting me see the light on the other side.

All funny aside. Thank you for working on this. Being able to use our them within the ckeditor is key to helping then end client's staff being able to easily update content and not have to guess how it will look once saved or previewed.

mel-miller’s picture

I think I may be having the same problem. Is there a way to manually clear this cache so that I can verify?

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

johnennew’s picture

Hi, Please find a re-roll for Drupal 8.6.x

Also included what I think is being asked for in #6

fenstrat’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 12: 2888723-12.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

Petr Illek’s picture

I've tested the patch on 8.7.1.
Working as expected – styles are updated inside CK Editor.
Also add in coding standards from #14.

Petr Illek’s picture

Status: Needs work » Needs review

Forgot to trigger the bot.

Status: Needs review » Needs work
Petr Illek’s picture

Try to fix the test.

Status: Needs review » Needs work
Petr Illek’s picture

Have overlooked the ckeditor_test.css. It wasn't in previous fail reports.

Petr Illek’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work
Petr Illek’s picture

kyberman’s picture

Thank you Petr! Everything is fine from my point of view.

fenstrat’s picture

Status: Needs review » Reviewed & tested by the community

Nice one, looks good.

+++ b/core/modules/ckeditor/src/Plugin/Editor/CKEditor.php
@@ -205,14 +217,14 @@ public function settingsForm(array $form, FormStateInterface $form_state, Editor
+          'rows' => [
+            0 => [
+              0 => [
+                'name' => 'All existing buttons',
+                'items' => $all_buttons,
+              ],
+            ],
+          ],

This is an unrelated CS change, but is probably ok to let go through.

Status: Reviewed & tested by the community » Needs work
yogeshmpawar’s picture

Status: Needs work » Reviewed & tested by the community

All looks good so setting back to RTBC! Tests failure is not related (see #3055648: Frequent random fail in \Drupal\Tests\media_library\FunctionalJavascript\MediaLibraryTest).

Status: Reviewed & tested by the community » Needs work
yogeshmpawar’s picture

Status: Needs work » Reviewed & tested by the community

Setting back to RTBC!
This is not happening anymore.

Wim Leers’s picture

Confirming RTBC.

This matches the logic in \Drupal\Core\Asset\CssCollectionRenderer and \Drupal\Core\Asset\JsCollectionRenderer.

Thanks everyone!

alexpott’s picture

+++ b/core/modules/ckeditor/src/Plugin/Editor/CKEditor.php
@@ -423,6 +435,11 @@ public function buildContentsCssJSSetting(Editor $editor) {
+    $query_string = $this->state->get('system.css_js_query_string') ?: '0';

You can supply a default value to get() - ->state->get(system.css_js_query_string', '0')

+++ b/core/modules/ckeditor/src/Plugin/Editor/CKEditor.php
@@ -74,13 +82,16 @@ class CKEditor extends EditorBase implements ContainerFactoryPluginInterface {
-  public function __construct(array $configuration, $plugin_id, $plugin_definition, CKEditorPluginManager $ckeditor_plugin_manager, ModuleHandlerInterface $module_handler, LanguageManagerInterface $language_manager, RendererInterface $renderer) {
+  public function __construct(array $configuration, $plugin_id, $plugin_definition, CKEditorPluginManager $ckeditor_plugin_manager, ModuleHandlerInterface $module_handler, LanguageManagerInterface $language_manager, RendererInterface $renderer, StateInterface $state) {

Adding a new argument to a constructor can often required adding it will a NULL and then deprecating that code path. We need to validate why we are not doing that here. For me it helps that there is a base class to extend from - \Drupal\editor\Plugin\EditorBase

Wim Leers’s picture

Hah.

\Drupal\Core\Asset\CssCollectionRenderer::render() does that wrong too then. Let's fix those lines too.

We need to validate why we are not doing that here.

A different text editor needs its own implementation, it can't subclass from another text editor's plugin.

For me it helps that there is a base class to extend from - \Drupal\editor\Plugin\EditorBase

This too :)

fenstrat’s picture

Status: Reviewed & tested by the community » Needs review
FileSize
10.35 KB
2.29 KB

Adds the default to state->get(), which also existed in \Drupal\Core\Asset\JsCollectionRenderer::render().

Not sure we need to add $state as a NULL param and deprecate that code path?

The last submitted patch, 33: 2888723-33.patch, failed testing. View results

Wim Leers’s picture

Status: Needs review » Needs work
            'href' => 'file_url_transform_relative:file_create_url:public://css/file-all?'

versus

            'href' => 'file_url_transform_relative:file_create_url:public://css/file-all?0'
anthony.bouch’s picture

Look forward to this one landing, however, for anyone that discovers this in the meantime, the ckeditor_stylesheets in the theme.info.yml can also be versioned. For example...

ckeditor_stylesheets:
  - css/base/base.css?v=32321321
  - css/components/components.css?v=32321321

Hope this helps.

fenstrat’s picture

Status: Needs work » Needs review
FileSize
26.98 KB
18.28 KB

Here's the fix for CssCollectionRendererUnitTest failures.

I've also included a deprecation notice for the new $state param to the constructor. It follows the format from #3018863: Make SystemMenuBlock's new constructor argument dependency optional.
In the deprecation notice I've just linked to this issue. I'm happy to create a change notice and link to that instead, but not sure if that's standard practice for these deprecations?

kim.pepper’s picture

It's been a bit of a moving target.

+++ b/core/modules/ckeditor/src/Plugin/Editor/CKEditor.php
@@ -74,13 +82,20 @@ class CKEditor extends EditorBase implements ContainerFactoryPluginInterface {
+    if ($state === NULL) {
+      @trigger_error('The state service must be passed to CKEditor::__construct(), it is required before Drupal 9.0.0. See https://www.drupal.org/node/2888723.', E_USER_DEPRECATED);
+      $state = \Drupal::service('state');
+    }

But I believe the current standard format is something like:

    if (!$state) {
      @trigger_error('Calling CKEditor::__construct() without the $state argument is deprecated in drupal:8.8.0. The $state argument is required in drupal:9.0.0. See https://www.drupal.org/node/2888723.', E_USER_DEPRECATED);
      $state = \Drupal::service('state');
    }
fenstrat’s picture

FileSize
27.07 KB
1.75 KB

@kim.pepper cheers! Attached updates the deprecation message format.

Also rather than just pointing to this issue, I've also gone ahead and created an actual CR https://www.drupal.org/node/3075102

Amit Dwivedi’s picture

@fenstrat Any Idea, how to fix this in Drupal 8.7.x ?

Edit - Patch #23 seems to work with 8.7.7

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

kim.pepper’s picture

FileSize
27.32 KB

Re-roll for drupal 8.8.0-beta1

sokru’s picture

Status: Needs review » Reviewed & tested by the community

Manually tested patch from #42 with 8.8.beta1.

alexpott’s picture

Version: 8.9.x-dev » 8.8.x-dev
Category: Task » Bug report
Status: Reviewed & tested by the community » Fixed

Committed bed9f25 and pushed to 9.0.x. Thanks!

Committed and pushed 33b9fe4861 to 8.9.x and 25420c01a6 to 8.8.x. Thanks!

Discussed with @catch and we agreed to backport to 8.8.x as this is a bugfix.

diff --git a/core/modules/ckeditor/src/Plugin/Editor/CKEditor.php b/core/modules/ckeditor/src/Plugin/Editor/CKEditor.php
index f62825af6f..da8f973ae4 100644
--- a/core/modules/ckeditor/src/Plugin/Editor/CKEditor.php
+++ b/core/modules/ckeditor/src/Plugin/Editor/CKEditor.php
@@ -85,16 +85,12 @@ class CKEditor extends EditorBase implements ContainerFactoryPluginInterface {
    * @param \Drupal\Core\State\StateInterface $state
    *   The state key/value store.
    */
-  public function __construct(array $configuration, $plugin_id, $plugin_definition, CKEditorPluginManager $ckeditor_plugin_manager, ModuleHandlerInterface $module_handler, LanguageManagerInterface $language_manager, RendererInterface $renderer, StateInterface $state = NULL) {
+  public function __construct(array $configuration, $plugin_id, $plugin_definition, CKEditorPluginManager $ckeditor_plugin_manager, ModuleHandlerInterface $module_handler, LanguageManagerInterface $language_manager, RendererInterface $renderer, StateInterface $state) {
     parent::__construct($configuration, $plugin_id, $plugin_definition);
     $this->ckeditorPluginManager = $ckeditor_plugin_manager;
     $this->moduleHandler = $module_handler;
     $this->languageManager = $language_manager;
     $this->renderer = $renderer;
-    if ($state === NULL) {
-      @trigger_error('Calling CKEditor::__construct() without the $state argument is deprecated in drupal:8.8.0. The $state argument is required in drupal:9.0.0. See https://www.drupal.org/node/3075102.', E_USER_DEPRECATED);
-      $state = \Drupal::service('state');
-    }
     $this->state = $state;
   }
 
diff --git a/core/modules/ckeditor/tests/src/Kernel/CKEditorTest.php b/core/modules/ckeditor/tests/src/Kernel/CKEditorTest.php
index 47b3ca5685..90148201b4 100644
--- a/core/modules/ckeditor/tests/src/Kernel/CKEditorTest.php
+++ b/core/modules/ckeditor/tests/src/Kernel/CKEditorTest.php
@@ -2,7 +2,6 @@
 
 namespace Drupal\Tests\ckeditor\Kernel;
 
-use Drupal\ckeditor\Plugin\Editor\CKEditor;
 use Drupal\KernelTests\KernelTestBase;
 use Drupal\language\Entity\ConfigurableLanguage;
 use Drupal\editor\Entity\Editor;
@@ -497,18 +496,4 @@ protected function getDefaultContentsCssConfig() {
     ];
   }
 
-  /**
-   * @deprecationMessage Calling CKEditor::__construct() without the $state argument is deprecated in drupal:8.8.0. The $state argument is required in drupal:9.0.0. See https://www.drupal.org/node/3075102.
-   * @group legacy
-   */
-  public function testConstructorDeprecation() {
-    $editor = new CKEditor([], 'test', ['provider' => 'test'], $this->container->get('plugin.manager.ckeditor.plugin'), $this->container->get('module_handler'), $this->container->get('language_manager'), $this->container->get('renderer'));
-
-    // Ensure the BC layer injects the correct object.
-    $reflection_object = new \ReflectionObject($editor);
-    $reflection_property = $reflection_object->getProperty('state');
-    $reflection_property->setAccessible(TRUE);
-    $this->assertSame($reflection_property->getValue($editor), $this->container->get('state'));
-  }
-
 }

I removed the deprecation from the 9.0.x commit. Doesn't need to be there.

  • alexpott committed bed9f25 on 9.0.x
    Issue #2888723 by fenstrat, Petr Illek, kim.pepper, johnennew, Wim Leers...

  • alexpott committed 33b9fe4 on 8.9.x
    Issue #2888723 by fenstrat, Petr Illek, kim.pepper, johnennew, Wim Leers...

  • alexpott committed 25420c0 on 8.8.x
    Issue #2888723 by fenstrat, Petr Illek, kim.pepper, johnennew, Wim Leers...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

AdamPS’s picture

Unfortunately this patch has broken code like this:

/**
 * Implements hook_ckeditor_css_alter().
 */
function XXX_ckeditor_css_alter(array &$css, Editor $editor) {
  $css[] = public://theme/my.css;
}

In buildContentsCssJSSetting() the code first appends the $query_string and then calls file_create_url(). For a public: path file_create_url() seems to escape the ? in the query string to become %3F.

The correct code is to make appending the query string the last stage in this function.

I have raised #3121503: Custom CKEditor CSS is broken with public:// URLs. If any of the authors of this patch could help repair the damage that would be very helpful thanks.