How to get the entity that field belongs to in the case of an entity reference field Here is my use case:

I have created a media bundle (FILM IMG) to store a media entity (image) field. I can manage it at admin/structure/media/manage/film_img/fields

In a content type named "FILM" , I have added a entity reference field which reference my "FILM IMG" media entity bundle.

I am also using file_field_path module to rename the uploaded images.
When I am adding a new image for a new Film, I would like to use hook_filefield_paths_process_file to rename my image file name.

This hook is providing me the media entity ($entity) as a parameter, but of course it is not providing the Film entity that I need (I need it to get some info to rename my file name)

Here is my question: How to get the "parent" entity from the referenced entity; 

In other words, with my use case: How to get my film node from the image media entity provided by the hook.
You can get that with an entity query:

// Get IDs of all film nodes that reference this entity
$nids = Drupal::entityQuery('node')
  -&gt;condition('type', 'film')
  -&gt;condition('field_foo.target_id', $entity-&gt;id())
  -&gt;execute();

// Load the nodes
$nodes = Drupal::entityManager()
  -&gt;getStorage('node')
  -&gt;loadMultiple($nids);