You are here

public function AssetMediaFactory::getMediaEntities in Media: Acquia DAM 8

Get all media entities an asset belongs to.

Parameters

int $assetId: The ID of the asset to get the media entities for.

string $bundle: A specific bundle to fetch the media entity from.

Return value

\Drupal\media\MediaInterface[]|false An array of media entities keyed by their bundles or FALSE on failure.

File

src/Service/AssetMediaFactory.php, line 122

Class

AssetMediaFactory
Class AssetMediaFactory.

Namespace

Drupal\media_acquiadam\Service

Code

public function getMediaEntities($assetId, $bundle = NULL) {
  $usage = $this
    ->getAssetUsage($assetId, $bundle);
  if (empty($usage)) {
    return FALSE;
  }
  foreach ($usage as $bundle => $entity_ids) {
    $usage[$bundle] = $this->mediaStorage
      ->loadMultiple($entity_ids);
  }
  return $usage;
}