I have a image "sample.jpg" (In media library) and I used this image in multiple custom blocks of different block types.
Now I need an information of all the custom blocks which are using "sample.jpg" image.
Drupal Answers is a question and answer site for Drupal developers and administrators. It only takes a minute to sign up.Sign up to join this community
You can use the
entityTypeManager, like this:
$blocks = \Drupal::entityTypeManager()->getStorage('block')->loadByProperties(['field_media_1' => $media_id, 'field_media_2' => $media_id]);
Where $media_id the the is of your media entity.
That will give you all the blocks that references that media entity.