- Issue created by @dan612
It is difficult to understand how to retrieve external urls to files which are stored in the DAM in a programmatic way, either via Twig or PHP.
Some use cases:
TBD
TBD
My current approach to handling this is to create a new service in Drupal that connects to the API. The method looks like this:
public function getAssetDamUrl(string $asset_id, string $format = 'original'): string {
$search_url = $this->getAssetLookupUrl($asset_id);
$access_token = $this->settings->get('dam_access_key');
$headers = [
'Authorization' => "Bearer " . $access_token,
];
try {
$request = $this->httpClient->request('GET', $search_url, ['headers' => $headers]);
$item_data = json_decode($request->getBody()->getContents(), TRUE);
return $item_data['embeds'][$format]['url'] ?? "";
}
catch (RequestException $e) {
return "";
}
}
But I wonder if:
Active
1.1
Code