public function getReferencingMedia($fid) {
    // Get media fields that reference files.
    $fields = $this->getReferencingFields('media', 'file');

    // Process field names, stripping off 'media.' and appending 'target_id'.
    $conditions = array_map(
      function ($field) {
        return ltrim($field, 'media.') . '.target_id';
      },
      $fields
    );

    // Query for media that reference this file.
    $query = $this->entityQuery->get('media', 'OR');
    foreach ($conditions as $condition) {
      $query->condition($condition, $fid);
    }

    return $this->entityTypeManager->getStorage('media')->loadMultiple($query->execute());
  }
public function getReferencingMedia($fid) {
    // Get media fields that reference files.
    $fields = $this->getReferencingFields('media', 'file');

    // Process field names, stripping off 'media.' and appending 'target_id'.
    $conditions = array_map(
      function ($field) {
        return ltrim($field, 'media.') . '.target_id';
      },
      $fields
    );

    // Query for media that reference this file.
    $query = $this->entityQuery->get('media', 'OR');
    foreach ($conditions as $condition) {
      $query->condition($condition, $fid);
    }

    return $this->entityTypeManager->getStorage('media')->loadMultiple($query->execute());
  }
public function getReferencingMedia ( $ fid ) { // Get media fields that reference files. $ fields = $ this -> getReferencingFields ( 'media' , 'file' ) ; // Process field names, stripping off 'media.' and appending 'target_id'. $ conditions = array_map ( function ( $ field ) { return ltrim ( $ field , 'media.' ) . '.target_id' ; } , $ fields ) ; // Query for media that reference this file. $ query = $ this -> entityQuery -> get ( 'media' , 'OR' ) ; foreach ( $ conditions as $ condition ) { $ query -> condition ( $ condition , $ fid ) ; } return $ this -> entityTypeManager -> getStorage ( 'media' ) -> loadMultiple ( $ query -> execute ( ) ) ; }
Gets Media that reference a File.

@param int $fid
File id.

@return \Drupal\media\MediaInterface[]
Array of media.

@throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
Calling getStorage() throws if the entity type doesn't exist.
@throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
Calling getStorage() throws if the storage handler couldn't be loaded.
Gets Media that reference a File .