Drupal core is releasing media embed filters along with the media library in December. These entities should be tracked as well. They are virtually the same as a entity embed token, but with `` instead.

Comments

pookmish created an issue. See original summary.

marcoscano’s picture

Status: Active » Needs work
Issue tags: +Needs tests

Thanks for contributing!

  1. +++ b/src/Plugin/EntityUsage/Track/MediaEmbed.php
    @@ -0,0 +1,39 @@
    + *   label = @Translation("Media Embed"),
    

    Maybe we can make it more explicit that this is from Drupal core? I'd say something like Media WYSIWYG Embed (Core) could be more helpful to users?

  2. +++ b/src/Plugin/EntityUsage/Track/MediaEmbed.php
    @@ -0,0 +1,39 @@
    + *   description = @Translation("Tracks relationships created with 'Media Embed' in formatted text fields."),
    

    Here too, let's explain that this comes from Drupal core.

    I actually think this could cause confusion on sites where core < 8.8, where this would do nothing. Maybe we should either:
    - Add some temporary code in the form builder that removes this plugin from the list if core < 8.8 (preferred), or
    - Improve this description to really make it clear that this option will only work with core >= 8.8

  3. +++ b/src/Plugin/EntityUsage/Track/MediaEmbed.php
    @@ -0,0 +1,39 @@
    +    foreach ($xpath->query('//drupal-media[@data-entity-type and @data-entity-uuid]') as $node) {
    

    It seems that Drupal core only deals with media, so the @data-entity-type restriction is unneeded here?

We will also need explicit test coverage for this.

Thanks!

oknate’s picture

Re #2
1. How about "Core Media Embed" or "Media Embed (Core). It's a filter, and technically it was added before it displayed in the WYSIWYG.
3. I think it's right to keep the restriction for data-entity-type. The filter has this code:

foreach ($xpath->query('//drupal-media[@data-entity-type="media" and normalize-space(@data-entity-uuid)!=""]') as $node) {

See \Drupal\media\Plugin\Filter\MediaEmbed::process()

So it won't process a drupal-media tag without the data-entity-type attribute. It was done this way to stay aligned with how Entity Embed works, see:

#2940029-63: Add an input filter to display embedded Media entities.4:

. . . by having this filter generate (and require) the same structure, we make it possible to in the future have a single coherent way of tracking usage. Without having to retroactively update all user-generated content.

chris matthews’s picture

StatusFileSize
new29.53 KB
new1.19 MB

1. How about "Core Media Embed" or "Media Embed (Core). It's a filter, and technically it was added before it displayed in the WYSIWYG.

My vote would be: "Tracks relationships created with Core's 'Embed media' filter in formatted text fields."

chris matthews’s picture

wim leers’s picture

Title: Track drupal-media tags in preparation for Drupal core 8.8 » Track <drupal-media> tags in preparation for Drupal core 8.8
Issue tags: +Media Initiative

Yes, this would be really valuable to have! 🙏🥳

berdir’s picture

Title: Track <drupal-media> tags in preparation for Drupal core 8.8 » Track <drupal-media> tags

Drupal 8.8 is out, so this isn't preparation anymore :)

dsdeiz’s picture

Status: Needs work » Needs review
StatusFileSize
new8.93 KB
new9.26 KB

Yeah, gave it a try. Wonder if this works.

johnpicozzi’s picture

Working with Entity Usage with core Media and found this issue. Sounds like the problem I'm having. However, I can't seem to get the media usage for an image using the tag in my body to display correctly. I think I have the correct configuration setup as other images added using entity reference fields are displaying usage correctly. Am I missing a checkbox some place or do I need to update the text format or something. Perfectly willing to test this if someone can point me in the correct direction.

Here is my current config

Entity Usage Config Page

Entity Usage Config Page

dsdeiz’s picture

Were you able to enable the "Media WYSIWYG Embed (Core)" filter?

johnpicozzi’s picture

Issue summary: View changes
StatusFileSize
new271.05 KB

@dsdeiz - Yes it would appear that that filter is enabled.

dsdeiz’s picture

Sorry, I meant "Media WYSIWYG Embed (Core)" tracking plugin in /admin/config/entity-usage/settings under "Enabled tracking plugins". This should've been enabled upon a fresh install of entity_usage. Just did a quick manual test and seems working on my end. I added the image via the "Insert from media library" button for CKeditor from media_library module.

johnpicozzi’s picture

@dsdeiz - I didn't see "Media WYSIWYG Embed (core)" in the list at first. I uninstalled and reinstalled the module and now it shows in the list. I re-ran the batch process and everything is working as expected. Thanks for the help!

chris burge’s picture

Patch #8 tests successfully for me. <drupal-media> elements are being tracked correctly.

  • marcoscano committed bca56dd on 8.x-2.x authored by dsdeiz
    Issue #3081407 by dsdeiz, pookmish, johnpicozzi, Chris Matthews, oknate...
marcoscano’s picture

Status: Needs review » Fixed
Issue tags: -Needs tests

Committed, thanks all!

johnpicozzi’s picture

Can we tag another release of the module or re-roll the patch in #8 to work with beta2?

marcoscano’s picture

Just tagged beta3 which includes this.

Thanks everyone!

Status: Fixed » Closed (fixed)

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