Problem/Motivation
I'm interested in altering/overriding the little bit of HTML markup that's output by core, in my case Drupal.theme.mediaEmbedEditButton
(from core/modules/media/js/media_embed_ckeditor.theme.js
), but without hacking core, of course. It seems I could do this in a custom theme by adding:
libraries-extend:
media/media_embed_ckeditor_theme:
- my_theme/my_library
(plus the info for my_library
in my_theme.libraries.yml
, and the JS file in my theme with the function that would return the new markup).
However, since this shows up in places like /node/add/page that only uses the admin theme (we're using Seven), such additions to my_theme
wouldn't apply. While it seems like I could make a bare-bones my_admin_theme
, pulling in Seven as base, I'd like to keep this override near other related customizations in a custom module (I also ran into other cans of worms when I tried this as a proof of concept).
What (else) I've tried
I tried putting in libraries-extend:
from above in my_module.info.yml
(plus the addition to my_module.libraries.yml
and the new JS, of course), but this didn't seem to work (kinda not surprising, since the docs I'm finding only seem to reference libraries-extend
in the same breath as themes). I also tried using hook_field_widget_form_alter()
in my_module.module
to attach my override library via $element['#attached']['library'][]
but didn't have luck there either.
Am I stuck with with making a custom admin theme if I want to use libraries-extend
? (I'm guessing this is also a problem for libraries-override
.) Or am I missing some hook or something I could instead add to my custom module to accomplish overriding the output made by Drupal.theme.mediaEmbedEditButton
?
Drupal.theme.mediaEmbedEditButton = function() { return 'html'; }
. Make sure your library has a dependency on the core library, so its JS is included first, and the browser should do the restDrupal.theme.mediaEmbedEditButton = function() { return 'custom button html'; }
(plus the necessarylibrary-extend
and custom library stuff to have it picked up). I definitely don't want to override and maintain a whole core library. Sorry if that wasn't clear from my long-winded text, haha. The small JS worked when I made a custom admin theme (other unrelated issues notwithstanding). Just thought it was odd to only be supported for themes, not modules. Maybe I should file a feature request.