Problem/Motivation
When using the filter_html
filter and any of <caption>
, <tbody>
, <thead>
, <tfoot>
, <th>
, <td>
, <tr>
tags are used in the "Allowed HTML tags" textarea, when revisiting the form, a javascript error is pops-up:
TypeError: Cannot read property 'tagName' of null in Drupal.behaviors.filterFilterHtmlUpdating
This is because of the following:
Allowed elements can be tag names + attributes. To get just the tag name, a "sandbox" div is used to get the tag name of a given allowed element parsing each allowed element.
The sandbox div
const sandbox = document.createElement('div');
Adding an "allowed tag" to the sandbox, then getting its tag name
sandbox.innerHTML = (the allowed element);
node = sandbox.firstChild;
tag = node.tagName.toLowerCase();
This breaks with table-related tag names as browsers do not allow these elements to have a <div>
as their immediate parent.
In other words, this has nothing to do with what other tags are allowed, it's because the browser will not allow making a table-related element the direct child of a <div>
, so sandbox.firstChild
is null in those cases.
Steps to reproduce:
- Enable
filter
andeditor
modules, - Create and edit a text format,
- Enable the Limit allowed HTML tags and correct faulty HTML filter,
- In the filter settings section, select the Limit allowed HTML tags and correct faulty HTML vertical tab,
- In the Allowed HTML tags textarea enter one or more of
<caption>
,<tbody>
,<thead>
,<tfoot>
,<th>
,<td>
,<tr>
tags, - Press the Save configuration button,
- Revisit the form and check the JS console.
The bug is proved by the attached "test only" patch.
Proposed resolution
Fix it.
Remaining tasks
None.
User interface changes
None.
API changes
None.
Data model changes
None.
Original report
I try to add the templates plugin of ckeditor into drupal8 to
achieve this http://knackforge.com/blog/sivaji/leveraging-ckeditor-template-theme-dru...
I created the module and the required files on this location:
git@github.com:baverhey/d8_ckeditor_templates.git
With information of these locations:
http://drupal.stackexchange.com/questions/139075/implementing-ckeditors-...
http://alexcoder.info/en/content/dobavlenie-plagina-ckeditor-v-drupal-8
https://www.youtube.com/watch?feature=player_detailpage&v=h9KV_VRvIG8#t=...
https://github.com/wwalc/moonocolor
There are no errors or any feedback why it is not working.
ckeditor plugin:
Its about the following plugins
http://ckeditor.com/addon/templates
any hints or tips are welcome.
Comment | File | Size | Author |
---|---|---|---|
#76 | 2556069-76.patch | 4.48 KB | lauriii |
Issue fork drupal-2556069
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
Wim LeersYou're basically just saying "it does not work".
Look at
CKEditorPluginInterface
and all of its implementations. You'll find plenty, plenty of examples that way.Comment #4
ikeigenwijs CreditAttribution: ikeigenwijs commentedSorry Wim, i still did not get it to work, its driving me and probably also you nuts.
On 2 different drupal 8.0.15 beta installs.
one clean one with just drupal core, nothing else.
Redid everything on d8.0.x master branche
I started from scratch with 3 different independent ckeditor add ons to enable.
all ckeditor version 4.4.x compatible
widgetbootstrap (the one i actually want) http://ckeditor.com/addon/widgetbootstrap
widgetbootstrap http://ckeditor.com/addon/widgetcommon
error i get with chrome js debugger: in aggregated version
Uncaught TypeError: Cannot read property 'icons' of null(anonymous function) @ ckeditor.js?v=4.4.7:214
(anonymous function) @ ckeditor.js?v=4.4.7:214
CKEDITOR.scriptLoader.load.k @ ckeditor.js?v=4.4.7:209
CKEDITOR.scriptLoader.load.m @ ckeditor.js?v=4.4.7:209
CKEDITOR.scriptLoader.load.q @ ckeditor.js?v=4.4.7:209
(anonymous function) @ ckeditor.js?v=4.4.7:210
used dif to see if i missed something and as proof of concept:
liststyle starting from the addon repository ,compared with liststyle from a drupal con talk these both do not crash ckeditor.
I get the buttons to show for all 3 on the config page, i can add the buttons to the toolbar.
But when editing a page the error occurs.
Following: https://www.drupal.org/node/2480333#comment-9948215
after recompiling ckeditor so i could see the code and use step by step debugger the part it hangs is:
in ckeditor.js line 14522
The first error seems to be related to image2
This is after dropping image2 in the ckeditor plugin folder
CKEDITOR.tools.extend( allPlugins, plugins );
var requiredPlugins = []; value requiredPlugins = ["image2"]
for ( var pluginName in plugins ) { value plugin="drupalimagecaption"
var plugin = plugins[ pluginName ], value plugin = Object {requires: "drupalimage", name: "drupalimagecaption", path: "http://d8_local/core/modules/ckeditor/js/plugins/drupalimagecaptio
requires = plugin && plugin.requires; value requires = "drupalimage"
if ( !initialized[ pluginName ] ) {
// Register all icons eventually defined by this plugin
After dropping image2 (just for testing) in the searched folder it gets bit further a couple of other modules follow. this is only in the recompiled verison i see a difference
drush rebuild-cache as a mad man at every step.
Checked and triple checked the CamelCasing, path, icon names, ... according to some posts, all to no avail.
clean d8 from git
Re tested everything with the 8.0.x branch same errors and results.
A push in the right direction would be much appreciated, its driving me nuts.
I attached the 2 modules
Comment #5
Wim LeersPlease edit your comment so that it becomes at least somewhat legible. I'm pretty sure an ICT manager is able to write better English and better formatted texts than this.
Comment #6
ikeigenwijs CreditAttribution: ikeigenwijs commentedI will try
Goal
Basic adaptation of widgetbootstrap ckeditor add-on using the CKEditorPluginInterface, CKEditorPluginButtonsInterface;
According to available examples and documentation i found.
Problem
Basic adaptation of widgetbootstrap gives following error on clean default drupal 8 install.
Possible causes
Things checked
What works
Assigning the buttons to the ckeditor toolbar with the 'missing' icons showing. No problems what so ever.
Code snippets
The origin of the error in ckeditor aggregated version
The origin of the error in ckeditor unaggregated version
ckeditor.js line 14522
Comment #7
Wim LeersThanks, that's infinitely better :)
I'll try to reproduce & debug locally!
Comment #8
Wim LeersMore accurate title.
Note that I probably won't have time for this until after RC1.
Comment #9
ikeigenwijs CreditAttribution: ikeigenwijs commentedI'm glad you like it. :D
I ll try some other things but i feel like the unaggregated ckeditor version using the build feature is not the same as the drupal core aggregated version. Is this correct?
Thank you for your time.
Comment #10
kevinquillen CreditAttribution: kevinquillen commentedI am also getting this same error. At a minimum I am trying to integrate the optional CodeSnippet module from CKEditor into D8 CKEditor following examples from DrupalImage plugin. I can see the button on the plugin list (also with xdebug) and I can assign it to the active toolbar. However, reloading the page gives me:
"Uncaught TypeError: Cannot read property 'icons' of null"
Everything I have done looks nearly the same as what was done in core to register and display those plugins, yet no dice. The form settings and options are displayed and saved correctly to config, but the Javascript error prevents it from working. Not sure how to rectify this error.
Comment #11
kevinquillen CreditAttribution: kevinquillen commentedI've put my code into a GitHub repository - I have debugged this as many ways as I can find and the same error persists.
https://github.com/kevinquillen/codesnippet
I have seen other modules work successfully, so I don't understand what is generating this error.
Examples:
Granted they are older..
The error appears to be thrown here in ckeditor.js:
However 'icons' is defined in the codesnippet plugin definition - so it would seem that the plugin object here is either missing it or not defined correctly.
I can drag the icon from the toolbar into the active toolbar, and the settings form appears. I can save the form. But the reload of the page, the settings form isn't there, and dragging and dropping the button back on the toolbar makes it appear.
Comment #12
kevinquillen CreditAttribution: kevinquillen commentedComment #13
kevinquillen CreditAttribution: kevinquillen commentedOkay, so this is interesting. I just updated to 8.0.0-rc3, in which updating the version of CKEditor occurred.
I no longer get this error:
"Uncaught TypeError: Cannot read property 'icons' of null"
But now, I get this new one:
"Uncaught TypeError: Cannot read property 'tagName' of null"
However, all plugins work, including my custom one - which wasn't before.
Comment #14
Wim LeersSeveral CKEditor fixes went in for RC3. One of them included updating CKEditor to version 4.5.4.
Can you please post the stacktrace? Just "Uncaught TypeError: Cannot read property 'tagName' of null" is pretty much useless. We need to know where that error is thrown. Thanks!
Comment #15
esclapes CreditAttribution: esclapes as a volunteer commentedI found the same error and this is what I found (BTW,I am not sure if this should be its own issue).
It seems to be a problem with
Drupal.behaviors.filterFilterHtmlUpdating._parseSetting
whent trying to parse the<caption> tag
, for some reasonsandbox.firstChild
returnsnull
.This is the stack trace
Comment #16
Wim LeersCan you reproduce this with 8.0.1?
Comment #17
esclapes CreditAttribution: esclapes as a volunteer commentedNo, I cannot reproduce on a fresh install of 8.0.1
Comment #18
Tim Bozeman CreditAttribution: Tim Bozeman as a volunteer and at CyberSolution commentedI'm on Drupal 8.0.4 and #15 seems to have resurfaced. If I add a CKEditor plugin and go to /admin/config/content/formats/manage/full_html I get a JS error.
Uncaught TypeError: Cannot read property 'tagName' of null
Same thing as #15 describes filter.filter_html.admin.js line 243.
sandbox.innerHTML = allowedTags[t];
When allowedTags[t] is
"<caption>"
innerHTML returns "" which makes node.tagName.toLowerCase() fail.Comment #19
Wim LeersThis is for now only affecting few people, so I won't have time for it soon probably. If you can work on a patch, this will get fixed much faster of course :)
Comment #20
Tim Bozeman CreditAttribution: Tim Bozeman as a volunteer and at CyberSolution for CyberSolution commentedThe problem is that we are adding table tags e.g. caption, tbody, thead, tfoot, th, td, tr without a table. Here's a first pass at a patch.
Comment #24
rutiolmaStill getting this error on 8.4.x-dev and this patch fixes it.
Comment #25
tstoecklerESlint complains about the latest patch:
Comment #26
claudiu.cristeaFixing the ESLint issues. And being an ugly bug, it should go in 8.3.x.
Comment #28
claudiu.cristeaComment #29
claudiu.cristeaComment #30
tstoecklerThanks! Re-RTBCing per #24.
Comment #31
jibranComment #33
claudiu.cristeaLooks unrelated?
Comment #34
claudiu.cristeaComment #35
star-szrSteps to reproduce in the issue summary would be great. Should this have a test or is that overkill?
Only criticals are going into 8.3.x so bumping up to 8.5.x and this could potentially be backported to 8.4.x. Looks like this patch needs to be reworked for ES6.
Comment #36
Robertliu CreditAttribution: Robertliu commented@claudiu.cristea #26
Thank you. That fixed this error.
Comment #37
pfrenssenIt's a bugfix so 8.4.x is still a valid target for this. This needs to be rerolled, it conflicts with the coding standards fixes that were done in #2880007: Auto-fix ESLint errors and warnings.
Comment #38
pfrenssenIt was actually the change to ES6 that caused the conflict. Rerolled it, my first time working with ES6 :)
I wasn't able to generate an interdiff since it was faster to apply the changes manually rather than rebase on the pre-ES6 code base, but the one line that I changed was this:
And moved the code to the ES6 file + regenerated the fallback JS.
Comment #40
dimr CreditAttribution: dimr at FIZ Karlsruhe commentedI have tried the patch #38 and it solved my problem.
Comment #41
alexpottLooks like we have missing test coverage. In order to commit a bug fix we need an automated to test to prove that we've fixed the bug and ensure that we don't break it again in the future. For more information about writing tests in Drupal 8 see the following links:
Comment #42
superlolo95 CreditAttribution: superlolo95 commented+1 for #38
Comment #44
claudiu.cristeaHere's the 'test only" patch.
Comment #45
claudiu.cristeaComment #46
claudiu.cristeaThe full patch. The interdiff is the patch from #44.
Comment #47
claudiu.cristeaComment #49
NickDickinsonWildeManually tested that the fix works. Test looks okay to me too.
Comment #50
lauriiiCan we get a review from the subsystem maintainers for the approach taken here?
Comment #52
BarisW CreditAttribution: BarisW commentedCan we get this in?
Comment #53
rromore CreditAttribution: rromore at Webspec commentedI can confirm that this is still an issue as of 8.7.3 and that #46 works for 8.7.3. The patch addresses the problem for the following tags: caption, tbody, thead, tfoot, th, td, and tr. However functionality is still broken for the following table-related tags: colgroup, col.
Comment #54
lukusI can confirm same for drupal/core (8.7.7) and #46.
Comment #55
claudiu.cristeaComment #56
claudiu.cristeaPassed the .es5.js file to Prettier and fixed the test.
Comment #57
claudiu.cristeaThis is marked as "Needs subsystem maintainer review" since October 2018, I'll assign to @Wim Leers for a feedback.
Comment #58
pfrenssenChanges made look good, just formatting fixes and adding the admin theme. Still needs maintainer review, so not setting to RTBC.
Comment #60
kevin.pfeifer CreditAttribution: kevin.pfeifer commentedI first created a duplicate Issue because I couldn't find this one (https://www.drupal.org/project/drupal/issues/3173615) but I can confirm, that the Patch from #56 fixed my problem!
Comment #61
claudiu.cristeaComment #62
marcvangendHere's a re-roll of the patch from #56 against Drupal core 9.1.x.
Comment #63
Wim LeersApologies for the long, long silence on this issue!
Special thanks to @claudiu.cristea for getting this issue back on track and completely overhauling the issue summary in #46 🙏
Test coverage looks great 👍
Comment #64
lauriiiComment #65
lauriiiI'm wondering if the issue summary is correct because I could reproduce the problem even when
<table>
, when<table>
is not allowed 🤔Comment #67
Proteo CreditAttribution: Proteo commentedTested patch in #62 on Drupal 9.1.5, it works and solves the issue.
Comment #70
bnjmnmAdded MR and set to needs review - the test failure that switched this to needs work was intentional.
Updated the issue summary to make it clear that configured allowed tags are not the issue, but appending elements to a
<div>
that semantically can't have a<div>
as its immediate parent.The solution in #62 will fail if the configured tags have attributes. It only works if the tag and nothing else is provided, which defeats the purpose as the purpose of that code is to extract the tag name from an item with attributes.
I changed this to use a jQuery solution, which despite jQuery's reputation seems to be the most effective way to do it. A jQuery object can accept an argument of a tag with attributes, and doesn't need a parent element. Once created, the tag name can be parsed easily.
Comment #72
nod_I agree that jQuery is a good solution here. It's purpose is to make life easier in those type of situations.
Code in the MR fixes the problem, there is a test, and a comment to explain why jquery is used.
The point in #65 about allowing table element when table is not allowed makes sense, follow-up feature request though :)
Comment #73
bnjmnmComment #75
lauriiiCommitted 88498c7 and pushed to 9.3.x. Thanks!
Leaving open for potential backport to 9.2.x.
Comment #76
lauriiiPosting patch to run tests against 9.2.x
Comment #78
lauriiiBackported to 9.2.x based on @xjm, @effulgentsia, and @alexpott providing +1 for the backport on Slack.