Problem/Motivation
The CKEditor5 Spoiler module doesn't attach the frontend JavaScript library to pages where spoiler content is rendered for anonymous users or when viewing content (not editing).
**The core issue:**
- When editing content, the `spoiler` library is attached via CKEditor5, which includes both the editor plugin and frontend functionality
- When viewing content (especially for anonymous users), CKEditor5 libraries are not loaded, so the spoiler toggle functionality doesn't work
The module provides the necessary assets in `ckeditor5_spoiler.libraries.yml`:
- `spoiler` - loaded with CKEditor5 (contains editor plugin + frontend JS)
- `spoiler.for.users` - standalone frontend library (CSS + JS for spoiler toggle functionality)
However, `spoiler.for.users` is never attached automatically, causing spoilers to be non-functional on the frontend.
Steps to reproduce
1. Install ckeditor5_spoiler module on Drupal 11
2. Create content with spoiler elements using CKEditor5
3. Save and view the content as an anonymous user (or any user not in edit mode)
4. Try clicking on a spoiler to expand/collapse it
5. Notice that the spoiler toggle functionality doesn't work
6. Check page source - `spoiler.js` from the `spoiler.for.users` library is not loaded
Proposed resolution
Add a **Filter plugin** that automatically detects spoiler content and attaches the necessary frontend library.
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | ckeditor5_spoiler--add_library_to_front.patch | 1.73 KB | kostiantyn |
Issue fork ckeditor5_spoiler-3558802
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
kostiantynI’ve made a patch, here it is. I’ll push it to Git a bit later.
Comment #3
kostiantynI’ve pushed the changes to Git, please test patch.
Comment #4
ivnishOh, how did I miss this?
Comment #7
ivnishThanks! I also added some fixes and hook_update. For existing sites it checks Spoiler button and if it added to CKEditor5 then filter_spoiler will enabled
Could you check the dev version? Don't forget to disable filter_spoiler before hook_update