I have a paragraph type with a media entity reference field field_paragraph_image_ref
.
I need to modify the media Twig template depending on a field value of the parent, which is a paragraph entity.
There are ways to get the parent entity of a paragraph, but media entities don't have a getParentEntity()
method. Also with _referringItem
I am unable to get up to the parent paragraph itself.
How can I get the field value from the parent paragraph in the media preprocess?
/**
* Implements hook_preprocess_HOOK().
*/
function hook_preprocess_media__picture__image_without_link(&$variables) {
$media = $variables['elements']['#media'];
// A method to get the parent entity, that I cannot find in
// var_dump(get_class_methods($media));
// and finally get a field value from the parent paragraph entity.
}
_referringItem
and look out for caching issues.