Problem/Motivation
This module provides functioanlity to insert a selected token into the currently active input/textarea/tinyMCE/CKEditor
/CodeMirror. This is handled in Drupal.behaviors.tokenInsert. I woul like to have the same functionality for CKEditor 5.
Steps to reproduce
Enable CKEditor5 for a field and try to insert a token via the click_insert functioanlity of the
token_tree_table render element. Nothing will happen.
Proposed resolution
Since there is no global CKEDITOR.currentInstance variable for CKEditor 5 i propose listening to the change:isFocused event to set a new drupalSettings.tokenFocusedCkeditor5 variable which saves the last active CKEditor5 editor instance.
This variable can then be used when trying to insert a token and no other field is focused.
Data model changes
New global JavaScript variable drupalSettings.tokenFocusedCkeditor5.
| Comment | File | Size | Author |
|---|---|---|---|
| #22 | token-click-insert-ckeditor5-fix-3334784.patch | 956 bytes | tarazingo |
| #13 | token-click-insert-ckeditor5-3334784-13.patch | 1.74 KB | vakulrai |
Issue fork token-3334784
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 #3
tgaugesComment #4
tgaugesComment #5
michaelsoetaertI've tested the proposed solution and can confirm that it works with
drupal/token 1.11.0.Comment #6
darvanenIt mostly works, however
drupalSettings.tokenFocusedCkeditor5doesn't get updated when the text_format is changed (found this while testing for #3262052: Support CKEditor 5.I'm looking into ways to improve this. I think I could override that setting from within the token_filter module when a user clicks the browser button using a CKEditor5 emitter, but I'd rather take a more holistic approach if possible.
Any ideas?
Comment #7
darvanenI decided to work around #6 within the token_filter plugin like this:
This change for token now looks good to me from manual testing.
Comment #8
darvanenOops
Comment #9
zaporyliePerhaps Token module could adapt to CKEditor's Content Placeholder feature, currently (awaiting) support via #3273754: Ckeditor5 readiness?
Comment #10
tyler36 commentedConfirming: MR!36 fixes issue for me on Drupal
10.1Comment #11
benstallings commentedI must be missing something... I've got MR!36 in place, but I don't see any interface element available to browse and insert tokens. Is there another step required to make this available?
Comment #12
darvanen#11: where are you not seeing it? The first step is to drag the button on to the toolbar in the configuration for your text filter which are accessed from /admin/config/content/formats
Comment #13
vakulrai commentedUploading the patch diff from : https://git.drupalcode.org/project/token/-/merge_requests/36/diffs for visibility.
Comment #14
a_nut commentedHi.
Like BenStellings #11 I've applied the patch to 1.12 on D10.1.4.
I've also applied the token module patch from the parent issue.
Both of the patches apply cleanly however there is no available button relating to Tokens in the CKEditor available list.
Is there a step needed to make this button available to drag to the toolbar?
Many thanks
Comment #15
darvanen@a_nut the CKEditor button is provided by token_filter in a related issue which is postponed on this one.
#3262052: Support CKEditor 5
Comment #16
a_nut commentedThanks for clarifying @darvanen. Appreciated!
Comment #19
berdirMerged.
Comment #20
berdirComment #22
tarazingo commentedHi everyone,
There is a small issue when you edit the node with paragraphs inside. If the paragraphs with the CKEditor field already exist, it works correctly, but when you add a new paragraph with the CKEditor field, the token insertion does not work.
Due to the presence of drupalSettings.tokenFocusedField and drupalSettings.tokenFocusedCkeditor5 in the same scope, the insertion is made to the hidden textarea field instead of the CKEditor widget.
I've attached a patch for the '^1.14' version of the module that resolves this issue.