Problem/Motivation
Without CSP Extras, the core AJAX system use jQuery "insert" method which seems to trigger correctly new behaviors added in the scripts loaded through AJAX.
The method used by CSP Extras does not and this generates problems when newly added script behaviors should be triggered immediately.
Steps to reproduce
- Create a Paragraph Type with a Wysiwyg Field
- Create a Content Type with a Paragraph field configured to use the widget "Paragraphs Classic", the Edit mode "closed" and "None" in the "Default paragraph type" select list.
- Go to the node creation page
- Press the button "Add [paragraph type]"
- The textarea field appears but the wysiwyg is not applied on
Proposed resolution
The problem here is that the scripts added by the CSP Extras method "add_assets" are not yet loaded when the textarea field is added by Drupal.
So the Drupal.attachBehaviors() is triggered to early, at a moment when the "CKEditor" behaviors are not available.
A solution could be to use Javascript Promises to trigger Drupal.attachBehaviors() after the scripts are loaded.
It's what the attach patch do.
| Comment | File | Size | Author |
|---|
Issue fork csp-3214916
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
nixou commentedComment #3
design.er commentedPatch from #2 is working like a charm. Thank you for putting it together.
Comment #4
gappleThank you for the issue report, patch, and review 🙂.
Drupal 8 and 9 continue to support IE 11, which doesn't appear to support
Promise- I would like to have a fallback to maintain compatibility with IE.----
If you're familiar with this issue, your feedback on these core issues which would remove the need for CSP to do this in D9 could also be valuable:
#3228351: Add loadjs library
#3228352: Add an add_js ajax command that uses promises
#1988968: Drupal.ajax does not guarantee that "add new JS file to page" commands have finished before calling said JS
Comment #7
bartlangelaanI changed the patch from #3 so it doesn't use promises anymore.
Please check out MR !3.
Comment #8
Taoufik Saadane commentedComment #10
gapple