Problem/Motivation
With the latest update here https://www.drupal.org/project/entity_embed/issues/3272732 I believe a bug was introduced with the loading of the Ckeditor 5 interface when a text format with the embed entities functionality enabled.
When I start a node creation page for any content with Ckeditor 5 field using a format that has the ability to embed entities the editor fails to load. When I switch to a format on that textarea that doesn't embed entities the editor loads. Also if I disable the embed entities ability in my format that is broken, and save it, the editor loads again for that format. The error I receive on the front end in the browser console is the following:
ckeditor5.js?s2yxym:201 TypeError: Cannot read properties of null (reading 'getAttribute')
at Object.callback (drupalentity.js?s2yxym:1:6039)
at i.create (ckeditor5-dll.js?v=35.4.0:5:416819)
at ckeditor5-dll.js?v=35.4.0:5:439488
at Array.map (<anonymous>)
at X.fillFromConfig (ckeditor5-dll.js?v=35.4.0:5:439398)
at $.register (ckeditor5-dll.js?v=35.4.0:5:555056)
at s.afterInit (drupalentity.js?s2yxym:1:6609)Not sure if anyone else is getting this issue. Hope this helps. Kind of a blocking issue for me to update a client site to Drupal 10. As they won't be able to manage any of their embedded media in any content without this patch. If I can help give any more context let me know.
My site is running Drupal 9 still and is in the process of being upgraded to Drupal 10 with this issue.
Others form the issue linked above are stating having this issue in drupal 10 as well.
This is also effecting users that may have employed a patch to the 1.4.0 version of the module in anticipation of this being included in the next version.
This is my first issue submission. Hopefully i did this correctly.
Steps to reproduce
- Create a text format with "Display embedded entities" enabled.
- Create a content type with a text format field using the new text format.
- Create new content of this content type.
- Notice Ckeditor 5 interface not loading.
Proposed resolution
Look into the Javascript to determine where the issue lies in loading the interface.
| Comment | File | Size | Author |
|---|---|---|---|
| #8 | entity_embed_oct_24_2023__changes_since_oct_4_not_working.patch | 104.79 KB | deasly |
| #8 | entity_embed_oct_4_2023__working.patch | 97.31 KB | deasly |
Issue fork entity_embed-3396133
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
deasly commentedComment #3
sahilgidwani commentedI am also getting this issue.
Comment #4
bnjmnmComment #5
deasly commentedI want to comment on your first two points then follow up with any information that i can to help resolve the issue.
My Environment:
Using Drupal 9, Entity embed 1.4.0 with a patch from (https://git.drupalcode.org/project/entity_embed/-/merge_requests/12.diff), and the embed module at 1.7 i am getting my above stated issue.
I have not yet installed on a fresh install. Sorry I didn't make this clear on the above but this is happening on an existing drupal install ckeditor 4 converted to ckeditor 5. And creating new content on a blank WYSIWYG Field. I'm including configs below for a format that has this issue.
Including a text format configs with issues (hope this helps):
editor.editor.full_html.yml
filter.format.full_html.yml
Comment #6
bnjmnmBased on the text format, the
drupal-entitytag allowed HTML is missing several attributes necessary for it to work with CKEditor 5. I see<drupal-entity data-entity-type data-entity-substitution data-embed-button>in the editor config, but significantly more attributes are required.<drupal-entity data-entity-type data-entity-uuid data-entity-embed-display data-entity-embed-display-settings data-view-mode data-align data-caption data-embed-button data-langcode alt title>This allowed attributes config should have been generated automatically on the switch to CKEditor 5 - functionality that is tested in
\Drupal\Tests\entity_embed\Kernel\UpgradePathTestBy any chance are you did you make the switch to using Entity Embed & CKEditor 5 prior to the Oct 20 using a patch/branch? In other words, was the switch done on code created so prior to #3272732: Drupal 10 & CKEditor 5 readiness being merged? That would explain why the allowed attributes aren't quite right, as well as the specific attribute related errors thrown in CKEditor 5's code.
Comment #7
trackleft2Deasly has a point, the last recommendation I saw for upgrading to CKEditor5 was to upgrade from CKEditor 4 before Drupal 10.
https://www.drupal.org/project/drupal/releases/10.1.0-beta1
Comment #8
deasly commentedI started the upgrade Friday night Oct 20th for this site. I didn't make the editor switch until this Monday the 23rd.
I added those attributes and the problem still persists. The Ckeditor 5 interface is still not loading for text formats using the entity embed functionality.
I created two patches applied to the 1.4 version of the module. One from the version of the patch that is working since Oct 4th and one patch off all the changes since then that aren't working for me up to the merge.
Attached are those patches. I am trying to figure out which "getAttribute" call is causing the issue I see from what I can see changed in the patch (entity_embed_oct_24_2023__changes_since_oct_4_not_working.patch). This is usually, from what I'm reading, occurring on a null element. So if something in the interface doesn't exist that's why we are getting this error.
it looks like everything is built into this file (drupalentity.js) so that's where I'm looking. and there appear to be 18 new instances from the Oct 4 patch on of calls to "getAttribute"
Comment #9
deasly commentedI found the offending line in "drupalentity.js"
It is minified so i just went through to find out which "getAttribute" call is causing the problem.
If i change the following in drupalentity.js it fixes the problem error on my end:
o=n.getAttribute("drupalEntityEntityUuid"),s=n.getAttribute("drupalEntityEntityType"),- to -
o="",s="",just feeding it an empty string to those values the interface comes back when i reload the page.
Now for what those do atm i still need to look. If anyone has any ideas please chime in.
Comment #10
deasly commentedNext update. That code exists as such in "entity_embed/js/ckeditor5_plugins/drupalentity/src/toolbar.js" line 60.
constants set:
in this function being run on load:
Comment #11
trackleft2@Deasly have you tried updating your config?
We use config_import_single to import single config files: https://www.drupal.org/project/config_import_single. Or you could use the config_sync UI for this.
As bnjmnm mentioned, there is an issue with your editor.editor.full_html.yml config. (We had the same issue)
Specifically this line
It needs to be this instead
Do you think ckeditor5 might be stripping those attributes since your config says not to allow them? Specifically these two?
Comment #12
deasly commented@trackleft2 I stated above in earlier comments that i set the above configuration on my side and the issues still persists.
I also stated above that this is new content (add not edit) and there are no embedded entities in the content so there is nothing to strip out. When creating this new node with and empty textarea this js fires off immediately and no Ckeditor 5 interface ever shows.
If i switch to a format that doesn't allow for embedded entities the Ckeditor interface loads fine. So this is a problem of JS running in the load of the format that i highlighted in my above comments.
This code is running on NULL right at load of the creation page and it shouldn't be or at least there should be some sort of empty detection because at this point there is nothing is selected, and nothing to select. So of course its going to be null and fire off a JS error when NULL is returned:
const element = editor.model.document.selection.getSelectedElement();how could there be a "editor.model.document.selection" when nothing has been selected yet when the page loads?
Comment #14
bnjmnmOpened MR that handles the absence of an element more gracefully. As noted in #12 - this callback is set up to be invoked when an element is selected. While it's not clear why it would run otherwise, it's easy enough to find those instances and exit early to avoid JS errors.
Comment #15
trackleft2I've imported your config into my site, with all of the dependencies, and now I see an error, are you patching https://www.drupal.org/project/video_embed_field? That module is not compatible with CKEditor5 AFAICT.
Comment #16
deasly commentedYup I've patched video embed field with the patch at https://www.drupal.org/project/video_embed_field/issues/3311063#comment-...
Gets the module into position to work with ckeditor 5.
Comment #17
deasly commented@bnjmnm I have 8.x-1.x-dev installed on the site and patched with your merge and its working perfectly.
@bnjmnm & @trackleft2 Thank so much for your help! I'm back in business. Thank you for taking your time to help me out. I really appreciate it.
Comment #18
geoffreyr commentedUsing the MR as a patch to fix the same problem. +1 agree on fixed, but there might be a few more people who might want to test it before RTBC.
Comment #19
siddharthjain commentedYes, using this MR(https://git.drupalcode.org/project/entity_embed/-/merge_requests/26) fixes the problem.
Thanks for the MR @bnjmnm
Comment #20
wim leersCKEditor 5 plugins must be built ("compiled" if you will) against a specific version of CKEditor 5. @bnjmnm built it specifically against Drupal 10.1.
The tests are also passing specifically on 10.1: https://git.drupalcode.org/project/entity_embed/-/jobs/201725
You may say "but the tests are also passing on 9.5", and you'd be right: https://git.drupalcode.org/project/entity_embed/-/jobs/201724
But that's ignoring the fact that the CKEditor 5 tests are skipped on Drupal 9: https://git.drupalcode.org/project/entity_embed/-/blame/ac6f2fe13b18f5f5...
@Dave Reid: this is something I mentioned briefly last Friday, and I should've emphasized it more. So to bring clarity to this situation now as well as in the future, I created #3396568: Test against current core minor (10.1), previous (10.0) and next (10.2).
@siddharthjain: Can you please share the markup on which it was crashing prior to applying @bnjmnm's https://git.drupalcode.org/project/entity_embed/-/merge_requests/26 MR? 🙏 It sounds like you actually have invalid Entity Embed markup … and I wonder how that is even possible 🤔😅
Comment #21
siddharthjain commented@Wim Leers Actually I am not able to recreate the issue after removing patch again and it is working fine, btw specifically what markup were you referring?
Comment #22
wim leersThe markup that you were editing.
The reason you cannot reproduce it anymore is most likely that you've modified the invalid markup and the Entity Embed CKEditor 5 JS plugin now generated the correct markup for you 😅
Comment #23
dercheffeUsing the MR https://git.drupalcode.org/project/entity_embed/-/merge_requests/26 as a patch on the latest dev of entity_embed on D9.5. It solves the issue and the editor renders great! thank you @bnjmnm
Comment #24
dercheffePossible to get a new stable release of entity_embed with with the MR included 🙏? It's a real release blocker for me and the EOL of D9.5 is here (and I'm still on CKEditor 4 because of this issue 🙈)
Comment #25
drupgirl commented+1 for stable release - this is a blocker for d10. Ty all.
Comment #26
marcelovani+1 for merging https://git.drupalcode.org/project/entity_embed/-/merge_requests/26
Comment #27
dercheffeTested from several people - so we can change the issue status? 🙂
Comment #28
wim leersDo all of these sites have such invalid markup? 😳 Quoting myself from #22:
Can y'all please share the markup which is causing Entity Embed HEAD to crash? 🙏
Comment #29
wim leersComment #30
deasly commented@Wim Leers I would have not changed the title because in my case this was happening when no content or markup was in place. A fresh node. If you would please change the title back so that others may still find the issue easier and we can get this merged in? You removed the core context of the issue title in which the Interface was not loading before this patch... And people are more likely to search on the instance of the interface not loading than the knowledge of it being just JS error which is to generic in my opinion.
Comment #31
dercheffeThis is my non-rendering markup code with following configuration:
Comment #32
dercheffeAfter upgrade to D10.1 with this test installation it renders correctly now suddenly without the patch 😳
Its very weird.
But would it harm to include the patch anyway?
Comment #33
damondt commentedCan confirm patch works, no longer can be sure of problematic markup since it's been said that ckeditor fixes it with this patch
Comment #34
marcelovani@Wim, in my case, the error was happening when creating new content. The entire toolbar was missing because of the js error.
Comment #35
dercheffeOk, did another test run with my local installation here.
My starting point:
What I did next:
Result: Now the markup was messed up like in my comment #31 and shown in a normal textarea-field. Ckeditor didn't render.
Then I performed upgrade from D9.5 to D10.1 with composer and "drush updb".
Result: Now ckedior worked probably
Result 2: The creation of new content worked like a charm too.
Conclusion:
I suggest to make a new (alpha/beta/stable ?) release of the current dev version. Perhaps a new branch making sense due to ckeditor 5 compatibility.
Comment #38
dave reidMR looked good and merged into 8.x-1.x. Thanks all for testing. Tagging a release shortly here.
Comment #39
wim leersIt seems like this simply didn't work correctly on
10.0— see #3396568-3: Test against current core minor (10.1), previous (10.0) and next (10.2). That explains #32 too 😊👍The test coverage Dave just merged in #3396568 will avoid future confusion around this! 👍