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 the 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.
Thank you @Jdrupal, with reference to your answer I have updated 'block' to 'block_content' and it is working fine.
$blocks = \Drupal::entityTypeManager() ->getStorage('block_content') ->loadByProperties(['logo1' => $media_id_1, 'logo2' => $media_id_2]);