Problem/Motivation
ckeditor5_mentions currently initializes mention feeds only when it finds select[data-editor-for="edit-body-0-value"]. That works for the default body field, but it fails on other CKEditor 5 instances where the source element id is different, such as comment forms or custom text fields.
In those cases, the mention plugin settings are attached, but the JS integration never runs because the selector is too specific. As a result, typing @ does not show any user suggestions even though the backend endpoint is available.
Steps to reproduce
- Enable ckeditor5_mentions
- Open a form that uses CKEditor 5, such as a comment form.
- Type @ followed by part of a real username.
- Observe that no mention dropdown appears.
- Inspect the page and see that the active editor uses a different data-editor-for value, not edit-body-0-value.
Proposed resolution
Update the mention integration to use the active CKEditor source element id instead of hardcoding edit-body-0-value.
The integration should:
- Read the current editor’s sourceElement.id.
- Look up the matching format control using [data-editor-for="${sourceElementId}"].
- Initialize mentions when that control exists, regardless of the field name.
- Keep the existing mention feed behavior unchanged.
Remaining tasks
User interface changes
None
API changes
None. This only affects mention initialization behavior in CKEditor 5.
Data model changes
None
| Comment | File | Size | Author |
|---|---|---|---|
| #5 | comment-form-active-format-selector.patch | 5.46 KB | drupal_simply_amazing |
Comments
Comment #2
drupal_simply_amazing commentedComment #3
drupal_simply_amazing commentedComment #4
drupal_simply_amazing commentedThe fix is to use the active editor’s own data-editor-for target instead of assuming a specific field ID. This makes the mention integration work consistently for both:
Comment #5
drupal_simply_amazing commentedComment #6
sujan shrestha commentedFixed in 2.0.x (commit f3512a1, release 2.0.1), with a different approach from the patch. The JS no longer reads the DOM at all: the feeds enabled for a text format are passed to each editor through its CKEditor 5 configuration (getDynamicPluginConfig()). Mentions now work in any field using the format (node body, comments, custom text fields), with or without a format selector. Thanks @drupal_simply_amazing for the report and patches.