Problem/Motivation
tag should be automatically added to the list of allowed HTML tags when embed button is enabled for the editor.
Steps:
1. Create entity embed button
2. Navigate to text formats configuration and drag and drop button to the editor (enable it)
3. Entity embed needs tag in the list of allowed tags. We need to add it manually.
Desired behaviour:
1. tag is added automatically when button enabled.
2. "Display embedded entities" should be automatically enabled (Not sure if this is possible - please review)
Proposed resolution
Remaining tasks
Original issue summary
According to #1894644: Unidirectional editor configuration -> filter settings syncing and #2510138: Unidirectional editor configuration -> filter settings syncing breaks when button name does not equal the command name, if we have our CKEditor plugin defined correctly, when the user drags & drops an Entity Embed button to the active editor toolbar that is using the allowed HTML filter, it *should* be automatically adding to the list of allowed tags. Currently this is not happening. May need to get Wim Leers help on this too.
| Comment | File | Size | Author |
|---|---|---|---|
| #43 | 2554687_43.patch | 638 bytes | slashrsm |
| #41 | 2554687-update-allowed-required-content.patch | 2.09 KB | dave reid |
| #41 | Selection_383.png | 30.27 KB | dave reid |
| #31 | interdiff.txt | 1.52 KB | slashrsm |
| #31 | 2554687_31.patch | 1.9 KB | slashrsm |
Comments
Comment #2
wim leershttp://docs.ckeditor.com/#!/guide/widget_sdk_tutorial_1-section-adjustin... has part of the answer.
In
js/plugins/drupalentity/plugin.js, change:to something like:
Now, because this is a custom element, that seriously complicates matters. I'm not sure about that either. Pinging the CKEditor folks.
Comment #3
dave reidWhen I drag the entity embed buttoin into an active toolbar, I see that in Drupal.behaviors.filterFilterHtmlUpdating.attach that the drupalEditorFeatureAdded event fires, but that the 'feature' object is
{name: undefined, rules: Array[0]}.Comment #4
dave reidHeaded into ckeditor/js/views/ControllerView and getFeatureForButton().
Comment #5
dave reidNone of the entity embed buttons are in this.model.get('buttonsToFeatures') nor this.model.get('featuresMetadata'). Interesting.
Comment #6
wim leersHrm, that is interesting (but especially weird).
Can you rename the commend from
editdrupalentityto justdrupalentityfor a minute and see if that helps?Comment #7
dave reidHrm, renaming the command to drupalentity in the JS did not help. I even tried changing the button ID to drupalentity in our CKEditor PHP plugin, and that did not help either.
Comment #8
wim leersI'll debug it when I find the time — hopefully this weekend, but quite possibly after DrupalCon Barcelona. This is not RC-blocking, I need to prioritize issues that are.
Comment #9
Reinmar commentedI'm not 100% sure, but I think that the problem is related to the way how you defined the button. There's no relation between the button and the allowed content. Usually it works like this:
1. When a button is added to the toolbar, the
editor.addFeature()method is called with that button.2. That button has a `command` property defined. This means that clicking this button will execute that command, but it also means that button.toFeature() will return the related command. Alternatively, the button can implement the CKEDITOR.feature interface directly, by defining the `allowedContent` and other properties in itself.
3. The command implements the CKEDITOR.feature interface, so it has the `allowedContent` and `requiredContent` properties. All that is registered to the ACF.
4. Later on, Drupal gets information about all features and their allowed/required content.
This does not work in your case, because your button does not define either the `allowedContent` property directly or the `command` property. That's because your case it's a bit special because you have one command which is executed by many different buttons. In this case I would define the `allowedContent` on the button despite the fact that it's already defined on the command.
Comment #10
wim leersWow, thanks, I'd never have been able to figure that out.
Dave Reid: hope this helps!
Comment #11
slashrsm commented#2614350: entity_embed's text filter should be enabled by default … but in which text formats? proposed to auto-enable relevant text filter too. It seems that we could do both in one go.
Is technique in #9 also useful to solve that?
Comment #12
axe312 commentedI'll have a look :)
Comment #13
wim leers@axe312: How is it going? :)
Comment #14
axe312 commentedAttended to dotCSS today, no Wifi was over there :)
Could you please share any info you got from the ckeditor guys? You mentioned in the IRC that you had a talk with them.
Comment #15
axe312 commentedWe should mention that Dave Reid did some work on this over here: https://github.com/drupal-media/entity_embed/pull/179
Comment #16
wim leersAll the info is in #9. Reinmar works for CKEditor.
Comment #17
axe312 commentedComment #18
pixelmord commentedAccording to this comment (https://www.drupal.org/node/2554687#comment-10330983) the functionality to automatically add the drupal-entity tag to the list of allowed content for HTML-correction needs to be added by defining this on the button itself due to the fact that these buttons/commands are not individually defined.
I tested that as you can see in this PR and when you now add the button to the editor toolbar you get the desired result.
I had to specify the attributes as required (!) otherwise only without attributes would have been added to the list.
I am not sure, if we can now get rid of the definition of the allowedContent attribute in other places, but that might need further testing.
Please review!
I created a PR on Github:
https://github.com/drupal-media/entity_embed/pull/205
or use attached patch
Comment #20
pixelmord commentedSorry, got my diff reversed :(
find the correct patch attached here
Comment #21
slashrsm commentedI tested this and it works as expected. I am also not sure about removing allowedContent from other places.
Will set to RTBC and keep it like this so other people can provide feedback.
Comment #22
wim leersThis should just match what #2638788: Required attributes wildcard in CKEditor plugin not compatible with filter system did. This is basically a follow-up to that issue.
Comment #23
CTaPByK commentedHere i just make change for allowedContent list of elements match to list from #2638788: Required attributes wildcard in CKEditor plugin not compatible with filter system, still works as expected.
Comment #25
wim leersComment #26
slashrsm commentedPatch does not apply.
Comment #27
CTaPByK commentedSorry for that, probably old version of entity_embed... I hope now will be ok.
Comment #28
dave reidRequired attributes are different from allowed attributes. We need to allow the alt and title attributes on the element, in addition to any data-* attributes. Right now this seems too restrictive.
Comment #29
wim leers#28 I don't understand. The
allowedContenton a button is only necessary to know what the absolute minimum tags/attributes are for this button's functionality to work correctly. This will then cause those tags/attributes to be whitelisted automatically for thefilter_htmlfilter's settings when dragging this button into the toolbar.This change has absolutely zero effect while using CKEditor. Drupal tells CKEditor which tags/attributes are allowed.
So, if you configure additional attributes to be allowed in your filter settings, it'll be allowed. This patch won't change that.
Comment #30
dave reidMaybe I have a hard time understanding the difference between requiredContent vs allowedContent. We know out of the box we want to allow alt and title, and any data attributes, so why can't we allow them by default? If a module that adds another element to the embed form will the site builder have to go and manually whitelist the new attribute every time?
Comment #31
slashrsm commentedI am a bit confused. Which alt and title attributes are we talking about? As far as I know entity_embed won't generate or use those two arguments in any way. There are data-align and data-caption attributes, which entity_embed mentions in some parts of documentation and we might want to include. However, none of the two actually work at the moment. We expose align in UI and we don't even do that for caption. There are already issues that are addressing this: #2645458: data-align and data-caption don't work with entity_embed and #2282957: Caption should work like the drupalimage plugin (editable in WYSIWYG, not in dialog). Let's fix those problems there.
Other's module needs is a valid point, but I'd say it is their responsibility to provide everything they need. Entity embed simply can't predict every possible situation that might appear in the future.
Another problem that I noticed with #27 is data-entity-id. Some time ago we decided to keep supporting it in text filters while completely removing it from CKEditor integration part. Somehow this attribute still sneaked into allowedContent and requiredContent for widget and command definition. This causes it to be required and results in embed button not working unless data-entity-id is included into the list of allowed attributes. I suspect we should remove it from requiredContent of both?
Comment #32
wim leers#31 looks great. Tentative RTBC, hopefully Dave Reid +1s.
Comment #33
dave reidalt and title attributes are fully supported if embedding an image entity using an image formatter.
The problem is that those other modules do not have a way to hook into providing their new attributes to be automatically whitelisted, aside from doing it manually, which is not idea DX. I would rather whitelist all data attributes entirely.
Comment #34
slashrsm commentedThat is stored in data-entity-embed-settings AFAIK, which is allowed.
I agree with @WimLeers in #2638788-7: Required attributes wildcard in CKEditor plugin not compatible with filter system. Allowing everything isn't the best practice. Explicitly whitelisting things that are really needed seems much safer.
Modules will extend functionality via EntityEmbedDisplay plugins and use data-entity-embed-settings to store things they need.
Comment #35
wim leersAn image formatter would run at filter time. So, the filter that transforms Entity Embed markup into its final form simply must run after the
filter_htmlfilter.Which you would need/want anyway, because image formatters could generate any markup, even crazy things like
<iframe>or<canvas>.So, I don't understand the reasoning in #33 at all.
Comment #36
dave reidThat wasn't the case a couple months ago - did that change? alt and title were stored as root attributes in that case last I knew.
I'm asking for data attributes to be whitelisted, nothing else. I don't understand the pushback at all.
Comment #37
dave reidHere's the condition I'm thinking about in my head:
There was a major desire (in D7 Media) to be able to override field values on the embedded entity. I was imagining that the module that wanted to support this would form alter the embed form (not providing its own EntityEmbedDisplay plugin, as it wants to support *all* display plugins), and add a new 'data-entity-field-name-value' attribute to the embed. I assumed that the data-entity-embed-settings should encapsulate the settings directly related to the display plugin itself, and not assumed to be a dumping ground for everything else. Especially important since those serialized settings are not namespaced in any way, so there is a desire to avoid having things dump arbitrary key/values in there.
Comment #38
wim leersAhhhh!
This makes sense. I am very much afraid about the current design, in which
data-entity-embed-settingsis indeed a dumping ground.Basically, the simplicity I described in #2628168-2: Clean up Entity Embed's data model.
Comment #39
dave reidComment #40
dave reidAdding the 'allowedContent' to editor.ui.addButton does not seem to be working at all. I'm not seeing any different settings in the Limit allowed HTML tags and correct faulty HTML on the filter page when I drag & drop an embed button to the toolbar on a new text format.
Comment #41
dave reidThis is what I'm currently working with. The auto-adding elements to the allowed HTML list does not appear to be working at all for me. In addition, I have the following JS console error when selecting CKEditor for a new text format: "Uncaught TypeError: f.format_tags.split is not a function"
Comment #42
dave reidComment #43
slashrsm commentedI rerolled #31 and tested it extensively. It seems to be working, but I noticed that it took quite some effort to clear browser cache on filter configuration page. Maybe that was the issue.
Comment #44
slashrsm commentedI don't think this is a beta blocker. While is is a nice UX improvement it can be added later (hopefully that won't be the case).
IS mentions two things: enabling required tag and attributes in the HTML filter and enabling entity embed filter. Current patch fixes the first problem. Solving the second problem will require a bit more custom code and will be much easier to achieve when/if #2561473: Namespace buttons is committed.
I suggest that we fix required tag/attrbutes as part of this issue and work on enabling the filter in a follow-up when the namespace issue is solved.
Comment #45
thenchev commentedThe browser cache was also the problem for me. Other than that it works.
Comment #47
slashrsm commentedCommitted. Thank you all!
Comment #49
oknateSorry to blow the dust off this issue, but I noticed that ImageFieldFormatter requires alt and title attributes on the drupal-entity in order to function properly. I have added an issue for that: see #3022768: Validate that `alt` and `title` are required attributes for `<drupal-entity>`, and ensure they're added by default.