You are here

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

Get an existing media entity for the given asset.

@BUG: Only returns the first media entity it finds. It's technically possible for assets to belong to different media entities.

Parameters

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

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

Return value

\Drupal\media\MediaInterface|false The media entity the given asset is associated with or FALSE.

2 calls to AssetMediaFactory::getMediaEntity()
AssetMediaFactory::getFileEntity in src/Service/AssetMediaFactory.php
Get an existing file entity for the given asset.
AssetMediaFactory::getMediaSource in src/Service/AssetMediaFactory.php
Get the media source an asset belongs to.

File

src/Service/AssetMediaFactory.php, line 101

Class

AssetMediaFactory
Class AssetMediaFactory.

Namespace

Drupal\media_acquiadam\Service

Code

public function getMediaEntity($assetId, $bundle = NULL) {
  $usage = $this
    ->getAssetUsage($assetId, $bundle);
  if (empty($usage)) {
    return FALSE;
  }
  $item = reset($usage);
  return !empty($item[0]) ? $this->mediaStorage
    ->load($item[0]) : FALSE;
}