Get parent entity in media preprocess hook I am having a paragraph with a media entity ref field   &quot;field_paragraph_image_ref&quot;.
I would need to modiy the media twig template depending on a field value of the parent, which is a paragraph entity.
How can i get the field value from the parent entity in the media preprocess
  function hook_preprocess_media__picture__image_without_link(array &amp;$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 
}
i have ended up doing:
function hook_preprocess_media__picture__image_without_link(array &amp;$variables) {
   $media = $variables['elements']['#media'];
   $parent = Drupal::entityTypeManager()-&gt;getStorage('paragraph')-&gt;loadByProperties([
    'field_paragraph_image_ref' =&gt; $media-&gt;id()
  ]);
   $parent = reset($parent);
   var_dump($parent-&gt;get(&quot;field_paragraph_image_link_page&quot;)-&gt;getValue();
}