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.

Comments

Dave Reid created an issue. See original summary.

wim leers’s picture

http://docs.ckeditor.com/#!/guide/widget_sdk_tutorial_1-section-adjustin... has part of the answer.

In js/plugins/drupalentity/plugin.js, change:

        allowedContent: 'drupal-entity[*]',
        requiredContent: 'drupal-entity[*]',

to something like:

        allowedContent: 'drupal-entity[data-entity-type,data-entity-uuid,data-entity-embed-*]',
        requiredContent: 'drupal-entity[data-entity-type,data-entity-uuid,data-entity-embed-*]',

Now, because this is a custom element, that seriously complicates matters. I'm not sure about that either. Pinging the CKEditor folks.

dave reid’s picture

When 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]}.

dave reid’s picture

Headed into ckeditor/js/views/ControllerView and getFeatureForButton().

dave reid’s picture

None of the entity embed buttons are in this.model.get('buttonsToFeatures') nor this.model.get('featuresMetadata'). Interesting.

wim leers’s picture

Hrm, that is interesting (but especially weird).

Can you rename the commend from editdrupalentity to just drupalentity for a minute and see if that helps?

dave reid’s picture

Hrm, 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.

wim leers’s picture

I'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.

Reinmar’s picture

I'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.

wim leers’s picture

Wow, thanks, I'd never have been able to figure that out.

Dave Reid: hope this helps!

slashrsm’s picture

Issue summary: View changes
Issue tags: +Media Initiative, +D8Media

#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?

axe312’s picture

Assigned: Unassigned » axe312

I'll have a look :)

wim leers’s picture

@axe312: How is it going? :)

axe312’s picture

Attended 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.

axe312’s picture

We should mention that Dave Reid did some work on this over here: https://github.com/drupal-media/entity_embed/pull/179

wim leers’s picture

All the info is in #9. Reinmar works for CKEditor.

axe312’s picture

Assigned: axe312 » Unassigned
pixelmord’s picture

Status: Active » Needs review
StatusFileSize
new593 bytes

According 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

Status: Needs review » Needs work

The last submitted patch, 18: entity_embed-automatically-add-tag_2554687_#18.patch, failed testing.

pixelmord’s picture

Status: Needs work » Needs review
StatusFileSize
new593 bytes

Sorry, got my diff reversed :(

find the correct patch attached here

slashrsm’s picture

Status: Needs review » Reviewed & tested by the community

I 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.

wim leers’s picture

Status: Reviewed & tested by the community » Needs work
Related issues: +#2638788: Required attributes wildcard in CKEditor plugin not compatible with filter system
+++ b/js/plugins/drupalentity/plugin.js
@@ -136,6 +136,7 @@
+            allowedContent: 'drupal-entity[!data-entity-type,!data-entity-id,!data-entity-uuid,!data-entity-embed-display,!data-entity-embed-settings]',

This 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.

CTaPByK’s picture

Status: Needs work » Needs review
StatusFileSize
new731 bytes

Here 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.

Status: Needs review » Needs work

The last submitted patch, 23: entity_embed-automatically-add-tag_2554687_23.patch, failed testing.

wim leers’s picture

Status: Needs work » Reviewed & tested by the community
slashrsm’s picture

Status: Reviewed & tested by the community » Needs work

Patch does not apply.

CTaPByK’s picture

Status: Needs work » Needs review
StatusFileSize
new577 bytes

Sorry for that, probably old version of entity_embed... I hope now will be ok.

dave reid’s picture

Status: Needs review » Needs work

Required 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.

wim leers’s picture

#28 I don't understand. The allowedContent on 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 the filter_html filter'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.

dave reid’s picture

Status: Needs work » Needs review

Maybe 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?

slashrsm’s picture

StatusFileSize
new1.9 KB
new1.52 KB

I 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?

wim leers’s picture

Status: Needs review » Reviewed & tested by the community

#31 looks great. Tentative RTBC, hopefully Dave Reid +1s.

dave reid’s picture

Status: Reviewed & tested by the community » Needs work

alt and title attributes are fully supported if embedding an image entity using an image formatter.

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.

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.

slashrsm’s picture

Status: Needs work » Needs review

alt and title attributes are fully supported if embedding an image entity using an image formatter.

That is stored in data-entity-embed-settings AFAIK, which is allowed.

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.

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.

wim leers’s picture

alt and title attributes are fully supported if embedding an image entity using an image formatter.

An 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_html filter.

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.

dave reid’s picture

That is stored in data-entity-embed-settings AFAIK, which is allowed.

That 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.

dave reid’s picture

Here'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.

wim leers’s picture

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.

Ahhhh!

This makes sense. I am very much afraid about the current design, in which data-entity-embed-settings is indeed a dumping ground.

Basically, the simplicity I described in #2628168-2: Clean up Entity Embed's data model.

dave reid’s picture

Issue tags: +beta blocker
dave reid’s picture

Status: Needs review » Needs work

Adding 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.

dave reid’s picture

This 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"

dave reid’s picture

slashrsm’s picture

Status: Needs work » Needs review
StatusFileSize
new638 bytes

I 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.

slashrsm’s picture

Category: Bug report » Task
Issue tags: -beta blocker

I 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.

thenchev’s picture

Status: Needs review » Reviewed & tested by the community

The browser cache was also the problem for me. Other than that it works.

  • slashrsm committed 08e5098 on 8.x-1.x
    Issue #2554687 by slashrsm, pixelmord, CTaPByK, Dave Reid, Wim Leers,...
slashrsm’s picture

Status: Reviewed & tested by the community » Fixed

Committed. Thank you all!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

oknate’s picture

Sorry 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.