Problem/Motivation

Entity embeds cache separately from the host entity's field that holds the CKEditor. This is unnecessary, and it makes it trickier to have per embed settings such as alt and title, which are rendered within the DOM of the embedded entity.

This comes from feedback from Wim Leers here: #2924391-66: [media entities] Regardless of @EntityEmbedDisplay plugin, Media entities representing a `image/*` MIME type should be able to have a per-embed `alt` and `title` (see comment 2)

Proposed resolution

Do not cache the embed separately.

Remaining tasks

  • Add patch
  • Add test coverage
  • Review

User interface changes

None

API changes

TBD

Data model changes

Not relevant

Comments

oknate created an issue. See original summary.

oknate’s picture

Issue summary: View changes
wim leers’s picture

Issue summary: View changes
Status: Active » Needs review
Issue tags: +D8 cacheability
StatusFileSize
new1.21 KB
wim leers’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests
oknate’s picture

For the test coverage, how do you think we should check the caching? I was thinking we could do a query against the cache_render table to look for the cids. We could assert that only the host entity (or field) was cached there.

wim leers’s picture

That could work: we could check there's only one cache item for multiple requests. However, that is diving into details.

I think this can be tested much more simply, without making the tests coupled to implementation details:

  1. Create an article with an embedded image media entity.
  2. Visit the resulting article, assert that the alt is inherited.
  3. Create another article with an embedded image media entity, but this time with an overridden alt.
  4. Visit the resulting article, assert that the alt is the overridden one.

With HEAD, this should fail, with this patch, it should pass.

wim leers’s picture

Issue tags: +Media Initiative

See #2924391-114: [media entities] Regardless of @EntityEmbedDisplay plugin, Media entities representing a `image/*` MIME type should be able to have a per-embed `alt` and `title`. We can directly copy/paste that test coverage over once #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` lands. But actually, we shouldn't keep that as functional JS test coverage, we should turn it into a functional PHP test: rather than inserting that test HTML in CKEditor, then saving the form, we can just create an entity like that in PHP, GET its canonical page and make our HTML assertions just like #114's interdiff was doing.

wim leers’s picture

oknate’s picture

Status: Needs work » Needs review
StatusFileSize
new6.47 KB
new7.22 KB
oknate’s picture

I see I have some extraneous code for filter format.

oknate’s picture

Removing filter format. That was unused code that I had brought over from my work on #3052482: Expand EntityEmbedFilter's test coverage: test many more edge cases, change to kernel test

The last submitted patch, 10: entity-embed-no-cache-3058872-10--TEST-ONLY.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

wim leers’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: -Needs tests
StatusFileSize
new4.02 KB
new6.38 KB

Right; this is technically not a bug in the filter, but it is exposed via the filter. I guess this could also have been part of #3052482: Expand EntityEmbedFilter's test coverage: test many more edge cases, change to kernel test.

But we're trying to make #3052482 solely about adding test coverage, and extracting any discovered bugs into an issue of its own will make it much easier to understand commit history too.

#12 looks great, but I found a few nits and some dead code, which I fixed.

P.S.: Note that this particular test could easily be converted to a kernel test, but I'll leave that to #3052482.

wim leers’s picture

Status: Reviewed & tested by the community » Fixed

🥳

  • Wim Leers committed 17b6c63 on 8.x-1.x authored by oknate
    Issue #3058872 by oknate, Wim Leers: Entity Embed render array shouldn't...

Status: Fixed » Closed (fixed)

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

oknate’s picture

Issue summary: View changes
oknate’s picture

Issue summary: View changes