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.

Command icon 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

kostiantyn created an issue. See original summary.

kostiantyn’s picture

I’ve made a patch, here it is. I’ll push it to Git a bit later.

kostiantyn’s picture

Assigned: kostiantyn » Unassigned
Status: Active » Needs review

I’ve pushed the changes to Git, please test patch.

ivnish’s picture

Priority: Normal » Critical

Oh, how did I miss this?

  • ivnish committed df7b3aca on 1.0.x
    fix: #3558802 Add conditional library attachment for frontend spoiler...
ivnish’s picture

Status: Needs review » Fixed

Thanks! 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

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

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