Problem/Motivation
Sometimes the data attribute conversion doesn't work well or the resulting media embed won't display properly depending on the configuration of the site. For example, the view mode conversion may not work in a case where it was configured to render in a given image style and thus the source view mode is not a valid media entity view mode.
Implementing an alter hook as part of the data attribute conversion function would allow custom modules to hook in and perform conversions appropriate to the site to ensure the desired end result.
Proposed resolution
Add the following to the start of the convertDataAttributes method:
\Drupal::moduleHandler()->alter('convert_entity_media_embed', $value);
This way custom modules can handle some or even all the attribute conversions before any of the current code kicks in.
Issue fork convert_entity_media_embed-3532681
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
teknocat commentedHaving applied the patch from my merge request, here's an example of using an alter hook in a site that uses the CKEditor media resize module. I can check if there's an image style in use, if so load it, get the image width and then use that to set all the appropriate attributes for that module to do its thing. But either way I just remove the data-entity-embed-display attribute because it's never valid anyway in my case, so it just ends up using the default display mode.