I tried to play with media_theme_suggestions_media, but it did not work in my case - seems that Drupal is not going into the hook_theme_suggestions_media
for example:
media-oembed-iframe--provider-vimeo.html
media-oembed-iframe--provider-youtube.html
I know I may have something wrong with media__source_ but It's not showing
the suggestion in the twig debug to know the right format
Thanks for all your work on the media module
Opened this issue as a follow up on the following lin
https://www.drupal.org/project/drupal/issues/2998091#comment-13013994
from
#2998091: Remote videos overflow their containing element
/**
* Implements hook_theme_suggestions_HOOK().
*/
function media_theme_suggestions_media(array $variables) {
$suggestions = [];
/** @var \Drupal\media\MediaInterface $media */
$media = $variables['elements']['#media'];
$sanitized_view_mode = strtr($variables['elements']['#view_mode'], '.', '_');
$suggestions[] = 'media__' . $sanitized_view_mode;
$suggestions[] = 'media__' . $media->bundle();
$suggestions[] = 'media__' . $media->bundle() . '__' . $sanitized_view_mode;
// Add suggestions based on the source plugin ID.
$source = $media->getSource();
if ($source instanceof DerivativeInspectionInterface) {
$source_id = $source->getBaseId();
$derivative_id = $source->getDerivativeId();
if ($derivative_id) {
$source_id .= '__derivative_' . $derivative_id;
}
}
else {
$source_id = $source->getPluginId();
}
$suggestions[] = "media__source_$source_id";
// If the source plugin uses oEmbed, add a suggestion based on the provider
// name, if available.
if ($source instanceof OEmbedInterface) {
$provider_id = $source->getMetadata($media, 'provider_name');
if ($provider_id) {
$provider_id = \Drupal::transliteration()->transliterate($provider_id);
$provider_id = preg_replace('/[^a-z0-9_]+/', '_', mb_strtolower($provider_id));
$suggestions[] = end($suggestions) . "__provider_$provider_id";
}
}
return $suggestions;
}
Comments
Comment #2
rajab natshahComment #3
rajab natshahComment #4
rajab natshahNoticed that
when the media bundle is image
then
But for oembed types remote_videos for example
Comment #5
rajab natshahComment #6
phenaproximaComment #7
phenaproximaHmm...I don't see how this, in general, could be happening unless you are theming oEmbed resources which (somehow) have no provider associated with them. Even so, this could use some test coverage; it is a blind spot.
Comment #8
rajab natshahThanks Adam for following
Please have a look at
https://www.drupal.org/project/drupal/issues/3044967#comment-13419910
You could find a list of issues, which needed to do this in number of cases
It's nice to have, not must have by core.
I know that the Media Team knows more and better on the subject
following with your direction.