It seems like while this issue was raised couple of times before, it was sidelined due to more pressing concerns. So lets decide this here once and for all. I'll try to list pros and cons of retaining the wrapper div from my understanding and others are welcome to add to the list:
PROS:
* In case of a failure, user could still see the wrapper and any placeholder text which might have been used in between. This behavior is kinda similar to alt text for an image. (Can be a con as well, in certain cases)
* Provides a standard point(DOM element) of refernce for theming and related tasks.
* Data attributes used for embed are separate from the actual embed so both can be handled differently, if required. (Kinda similar to how iframes work)
* Others?
CONS:
* More clean output.
* In case embed fails, no stray divs will be produced. (Might be desired in some cases)
* Inline elements like images may become block elements due to wrapper. (Can try a workaround for this?)
* Others?
Comment | File | Size | Author |
---|---|---|---|
#15 | 2547085-15-FAIL-test-only.patch | 3.54 KB | Wim Leers |
| |||
#15 | 2547085-15.patch | 4.29 KB | Wim Leers |
|
Comments
Comment #2
f2boot CreditAttribution: f2boot commentedCONS:
Quotes or other text references often need to be inline elements (entity_embed would be a great step forward to ease the creation of hypermedia website for scholarly associations or learned societies)
Comment #3
Dave ReidYeah, we've seen in File Entity that having the wrapping div is very much undesirable in a lot of cases. If there is a failure (like the entity fails to load) then we should log it.
Maybe we could do the best of both worlds and make it configurable from the button what behavior to use (replace contents inside and leave wrapping div, or replace div entirely)?
Comment #4
cs_shadow CreditAttribution: cs_shadow commentedI can definitely imagine cases where wrapping div can cause problems.
I like the idea of making it configurable and on the same note, should we also add a configuration option about what to do in case of a failure - retain the wrapper or just log the error?
Comment #5
cs_shadow CreditAttribution: cs_shadow commentedAnother issue that we'll need to address if we decide to go with this configuration plan - This works well for embeds created with a button but what happens when no button is used and the filter is invoked directly. There are three ways that I can think of at the moment to handle this case:
- Replace/Retain always, whatever is default behavior
- Allow this default behavior to be configurable (this would be global module-level config)
- Add a data attribute to specify this
Comment #6
Dave ReidI'm starting to feel stronger and stronger about replacing always.
Comment #7
cs_shadow CreditAttribution: cs_shadow commentedAlright, lets do this - lets remove the wrapping div. But I think that we should still copy all the data attributes to the first child of the wrapping div
Comment #8
Dave ReidI feel strongly about not copying the data attributes still. If someone wants that behavior, I think they should be able to do so using hook_entity_embed_alter(). I'd rather just replace the content like all other filters do.
Comment #9
Dave ReidComment #10
Dave ReidComment #11
tkoleary CreditAttribution: tkoleary at Acquia commentedI doing this this might have been a mistake.
The first thing I wanted to do was create a class and add it to the "styles" dropdown in CK so I could style embedded entities. This was not possible because there was no wrapping div.
Assuming a use case (as I am) in which the author does not have the ability to view source, in order to style an embedded entity they need to:
1. Create some text
2. Style the text from the styles dropdown with div element style
3. select the text
4. click the embed link and embed the entity which replaces the text and is now wrapped in the div with the class
After this the embedded entity is still not styled in the WYSIWYG, but is styled on the live page.
If it's wrapped in a div: select it, style it, done. That seems like a far more usable feature.
Comment #12
Wim Leers#8:
+1000
#11:
You're misunderstanding this. We're talking about the markup that Entity Embed transforms:
<drupal-entity data-entity-type="node" data-entity-uuid=… />
. Currently, the content that that the filter should put in its place, is not replacing that<drupal-entity>
tag. It's being added as the child of the<drupal-entity>
tag.What you're talking about is that any
class
attribute set on<drupal-entity>
should persist, should make its way onto the final HTML.i.e.:
->
That is true, and is a separate problem. Entity Embed should behave like
\Drupal\filter\Plugin\Filter\FilterCaption
does in that case: it correctly passes on classes.I ran into this bug in yet another way: via the test coverage while working on #2628358: Disallow <div>, only allow <drupal-entity>:
It says "test that anything else than is NOT replaced" … but then it tests that it DOES get replaced! Yet it also tests that
</not-drupal-entity>
still exists… And both tests pass! That is not logically possible!Except this bug makes it possible: because we never ever replace the original DOM node, we also cannot reliably test some cases, because the original HTML is never actually replaced.
Working on this.
Comment #13
Wim LeersThis blocks #2628358: Disallow <div>, only allow <drupal-entity>.
Comment #14
Wim LeersBetter title.
Comment #15
Wim LeersJust using
\Drupal\embed\DomHelperTrait::replaceNodeContent()
instead of\Drupal\embed\DomHelperTrait::setNodeContent()
is all that's necessary!Test coverage updated.
Note that these bits of test changes are due to #12 and they will be fixed in #2628358: Disallow <div>, only allow <drupal-entity>:
Comment #16
Wim LeersBut… HAH! That won't actually work, because
embed
'sreplaceNodeContent()
is broken: see #2602316: Allow any HTML as content for replaceNodeContent. It will only actually import the first DOM node. And the first DOM node when rendering an article template happens to be… a text DOM node with a newline in it. The second DOM node is the<article class="type-node" …>
HTML that we expect.So, with the above, tests actually fail for both patches because
embed
is broken…Now working on #2602316: Allow any HTML as content for replaceNodeContent.
Comment #19
Wim LeersAs predicted, both patches failed.
Forgot to add a related issue.
Comment #20
tkoleary CreditAttribution: tkoleary at Acquia commented@Wim Leers
IIRC the class was not even added to drupal-entity when I attempted to do so via the styles dropdown, but maybe there was just no visual feedback?
Comment #21
slashrsm CreditAttribution: slashrsm at MD Systems GmbH commentedEmbed patch was committed. Re-testing.
Comment #23
slashrsm CreditAttribution: slashrsm at MD Systems GmbH commentedFail was expected. No idea why bot didn't recognize test only patch. Committing this as it blocks us on other issues.
If we still want to preserve classes let's do that in a separate issue. Keeping in rendered output isn't option IMO.
Thank you all!
Comment #25
Wim LeersI will open a separate issue for the class attribute persistence support.
Comment #26
Wim LeersComment #27
Wim Leers@tkoleary: opened that separate issue as promised: #2628712: Persist the classes specified in <drupal-entity class> onto the rendered entity.