protected function AssetFileEntityHelper::fetchRemoteAssetData in Media: Acquia DAM 8
Fetches binary asset data from a remote source.
Parameters
\cweagans\webdam\Entity\Asset $asset: The asset to fetch data for.
string $destination_folder: The destination folder to save the asset to.
string $destination_path: An optional variable that will contain the final path in case it was adjusted.
Return value
false|string The remote asset contents or FALSE on failure.
1 call to AssetFileEntityHelper::fetchRemoteAssetData()
- AssetFileEntityHelper::createNewFile in src/
Service/ AssetFileEntityHelper.php - Creates a new file for an asset.
File
- src/
Service/ AssetFileEntityHelper.php, line 250
Class
- AssetFileEntityHelper
- Class AssetFileEntityHelper.
Namespace
Drupal\media_acquiadam\ServiceCode
protected function fetchRemoteAssetData(Asset $asset, $destination_folder, &$destination_path = NULL) {
// If the module was configured to enforce an image size limit then we need
// to grab the nearest matching pre-created size.
$mimetype = $this->assetImageHelper
->getMimeTypeFromFileType($asset->filetype);
$size_limit = $this->config
->get('size_limit');
$is_image = 'image' == $mimetype['discrete'];
$use_tn = !empty($size_limit) && -1 != $size_limit && $is_image;
if ($use_tn) {
$largest_tn = $this->assetImageHelper
->getThumbnailUrlBySize($asset, $size_limit);
if (empty($largest_tn)) {
$this->loggerChannel
->warning('Unable to save file for asset ID @asset_id. Largest thumbnail not found.', [
'@asset_id' => $asset->id,
]);
return FALSE;
}
$file_contents = $this
->phpFileGetContents($largest_tn);
// The DAM can return a different filetype from the original asset type,
// so we need to handle that scenario by updating the target filename.
$destination_path = $this
->getNewDestinationByUri($destination_folder, $largest_tn, $asset->name);
}
else {
$file_contents = $this->acquiaDamClient
->downloadAsset($asset->id);
}
return $file_contents;
}