public function AssetMediaFactory::getAssetUsage in Media: Acquia DAM 8
Get a collection of media entities using the given asset ID.
Parameters
int $assetId: The asset ID to check usages of.
string $bundle: A media bundle to filter usage information by.
Return value
array An array of media IDs using the given asset ID, keyed by their bundle.
2 calls to AssetMediaFactory::getAssetUsage()
- AssetMediaFactory::getMediaEntities in src/
Service/ AssetMediaFactory.php - Get all media entities an asset belongs to.
- AssetMediaFactory::getMediaEntity in src/
Service/ AssetMediaFactory.php - Get an existing media entity for the given asset.
File
- src/
Service/ AssetMediaFactory.php, line 146
Class
- AssetMediaFactory
- Class AssetMediaFactory.
Namespace
Drupal\media_acquiadam\ServiceCode
public function getAssetUsage($assetId, $bundle = NULL) {
$asset_id_fields = $this
->getAssetIdFields();
if (empty($asset_id_fields)) {
return [];
}
$usages = [];
foreach ($asset_id_fields as $key => $field) {
if (!empty($bundle) && $key != $bundle) {
continue;
}
$media_ids = $this
->getMediaBundleFields($key, $field, $assetId);
if (!empty($media_ids)) {
$usages[$key] = array_values($media_ids);
}
}
return $usages;
}