Problem/Motivation
I am working with Entity Embed module and when I add an entity to the form using the Wysiwyg button, the entities are all mixed up with the text and its not easy to see where an entity embed starts and stops.

This is how it looks now, there is no clear separation or indication.
Proposed resolution
Add css rule for drupal-entity to make it a block element.

I would like to propose to display an outline around the entity, see
See it in action:

Remaining tasks
- review
User interface changes
- yellow border shown when hovering over drupal-entity elements within ckeditor.
API changes
- none
Data model changes
- none
| Comment | File | Size | Author |
|---|---|---|---|
| #31 | 3037316-31.patch | 391 bytes | oknate |
| #24 | 3037316-24.patch | 1 KB | wim leers |
Comments
Comment #2
marcelovaniComment #3
marcelovaniIt turns out, just displaying it as block does the trick.
Comment #4
marcelovaniComment #6
wim leersThanks! Moving to the right project.
Comment #7
oknateHere's an updated patch that alters the ckeditor css from the entity_embed module.
Comment #8
oknateComment #9
wim leersThanks!
Unfortunately this doesn't work well for left-aligned and right-aligned embeds. See attached screencast.
Comment #10
oknateThe easy solution was too good to be true. It also wouldn't work if drupal-entity elements are eventually allowed to be inline.
Comment #11
wim leersI compared it to the
image2plugin's behavior (which core'sdrupalimageplugin extends), and it usesdisplay: inline-block, which has much better results.Comment #12
oknateThe outline looks good now, there's no white space between the outline and the image. But I'm having trouble testing right or center align. On a standard install of Drupal 8.7.1, I can't get embed to change position when I use the align radios, as you're doing in the screenshot. I have the align filter on. Any idea why that's not working for me? I'd like to test it displaying on the right with the outline displaying correctly.
Comment #13
oknateIt looks like the align only works if you have a caption, see #2645458: data-align and data-caption don't work with entity_embed
Comment #14
oknateUsing inline-block allows the outline to look good, but it breaks data-align functionality. Right and center alignment no longer work with the caption.
On a side note the data-align functionality without the caption is broken.
I created an issue for that:
#3058870: data-align should work without caption
Comment #15
oknateI started looking at this again, and the css change is unnecessary, I think. Removing it, I still see the yellow outline (when using a caption). The problem is that it doesn't work without the caption.
See #3058870: data-align should work without caption
Strangely, after you remove the caption it seems to keep working. But if you remove the element and add it back without a caption, it doesn't work.
Comment #16
oknateSince it was working only when the caption was applied, I just borrowed the css that filter caption is applying.
Filter code:
Then made the selector more specific:
There must be some kind of js interaction with the css rules. Adding display block to the child element as filter caption does seems to fix it and still allows the alignment to work.
Comment #17
oknateComment #18
oknateThis I believe fixes both the outline and the alignment in 3058870.
When data-align isn't present, we want inline-block, so that it wraps the element. When data-align is present, the element floats and therefore, we can't have inline-block on there. In that case, the rule borrowed from the caption filter where the child element is a block fixes the outline.
Comment #19
oknateI closed #3058870: data-align should work without caption. I couldn't recreate it. Which is odd because I was seeing it this morning, see #12.
So I am a little lost now on how to manually test this issue and that one. I'm not sure if some sort caching is showing it fixed now, or some sort of caching or config problem was breaking it earlier.
I'll have to start over testing the two issues with a fresh perspective a different day.
Comment #20
wim leersThis causes no outline to show up when the embed is aligned to the center Changing it to
inheritfixes that. But then left and right alignment break. The attached patch seems to work better.That being said, there are still problems, such as
data-align=centernot working withoutdata-caption(is that what #3058870: data-align should work without caption was about?).But AFAICT the attached patch does fix the reported problem, in all possible permutations: with/without caption, no alignment/left/center/right, and all combinations of them. Despite the CSS being questionable, the UX improvement is not questionable, so I think we should go ahead and commit this.
Comment #21
oknateYes, I think it gets us closer. Plus, now that the css file is there, someone in the community is more likely to experiment with the settings and perhaps improve it.
Comment #22
marcelovaniNice job, I would like to be able to help but I am a back end developer with limited CSS skills
Comment #23
oknate@marcelovani, you can help by testing out the patch and verifying if it works for you.
Comment #24
wim leersAfter more hours of struggling with this than I would like (also for #2544020-28: CKEditor plugin not written with CKEditor >=4.4 in mind; rewrite it based on core's `drupalimage` plugin), I found a solution for #20:
display: flex. Core is already using this in many places, so it should be fine for us to use this too. This was not available five years ago :)I tested every permutation, these are my conclusions:
(from better to worse)
This largely confirms what we already concluded, but this now documents it with more precision.
All this
initialandinheritis not very explicit. I'm making it more explicit. To match the above table.This is unnecessary, the
.caption > *rule infilter.caption.cssalready does exactly this!Removing it.
Attributing this to @oknate instead of me because I accidentally attributed #2924391: [media entities] Regardless of @EntityEmbedDisplay plugin, Media entities representing a `image/*` MIME type should be able to have a per-embed `alt` and `title` to me instead of @oknate.
Comment #26
wim leers🚢
Comment #27
oknateI'm seeing whitespace between the outline and the embed when align is set to none and there is a caption.
Steps to recreate:
Expected, there should be no white space between the outline and the embedded entity.
Actual, for all view modes selected there's white space when align set to none.
It does work for other options, and it works for align none with no caption. There is no white space between the outline and the embed with align options other than none.
Comment #28
wim leersThat is just the browser's style sheet imposing that margin by default. That is the space taken up by the
<figure>tag and hence the captioned embed. So this is accurate.The scope of this issue was to ensure that an accurate outline exists in all situations (see table in #24 for all possible situations).
I understand what you want, but it cannot be achieved through just CSS.
The only way to do what you want is to significantly change how the Entity Embed CKEditor plugin works: it would require removing the
<drupal-entity>tag from the DOM. (This is implicitly what thedrupalimageCKEditor widget in core does.)So let's please do that in a follow-up issue. This issue solved the accessibility/usability issue, now it's down to a cosmetic issue :)
Comment #29
oknateOk, thanks for the thorough explanation why this isn't possible when the align option is set to none. The fact that the outline is showing up at all is huge!
Comment #30
oknateThere's one CS fail introduced in the patch:
drupal-entity[data-align=right]{should be
drupal-entity[data-align=right] {according to linter.
Comment #31
oknateHere's a patch for the coding standard issue in #30.
Comment #33
wim leersPushed that too :)