AcquiadamController.php in Media: Acquia DAM 8
File
src/Controller/AcquiadamController.php
View source
<?php
namespace Drupal\media_acquiadam\Controller;
use Drupal\Core\Controller\ControllerBase;
use Drupal\media_acquiadam\AcquiadamInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class AcquiadamController extends ControllerBase {
protected $acquiadam;
protected $asset;
public function __construct(AcquiadamInterface $acquiadam) {
$this->acquiadam = $acquiadam;
}
public static function create(ContainerInterface $container) {
return new static($container
->get('media_acquiadam.acquiadam'));
}
public function assetDetailsPageTitle($assetId) {
$asset = $this
->getAsset($assetId);
return $this
->t("Asset details: %filename", [
'%filename' => $asset->filename,
]);
}
protected function getAsset($assetId) {
if (!isset($this->asset)) {
$this->asset = $this->acquiadam
->getAsset($assetId, TRUE);
}
return $this->asset;
}
public function assetDetailsPage($assetId) {
$asset = $this
->getAsset($assetId);
$asset_attributes = [
'base_properties' => [],
'additional_metadata' => [],
];
$asset_attributes['base_properties']['Asset ID'] = $asset->id;
$asset_attributes['base_properties']['Status'] = $asset->status;
$asset_attributes['base_properties']['Filename'] = $asset->filename;
$asset_attributes['base_properties']['Version'] = $asset->version;
$asset_attributes['base_properties']['Description'] = $asset->description;
$asset_attributes['base_properties']['Width'] = $asset->width;
$asset_attributes['base_properties']['Height'] = $asset->height;
$asset_attributes['base_properties']['Filetype'] = $asset->filetype;
$asset_attributes['base_properties']['Color space'] = $asset->colorspace;
$asset_attributes['base_properties']['Date created'] = $asset->datecreated;
$asset_attributes['base_properties']['Date modified'] = $asset->datemodified;
$asset_attributes['base_properties']['Owner'] = $asset->user->name;
$asset_attributes['base_properties']['Folder'] = $asset->folder->name;
if (isset($asset->expiration)) {
$asset_attributes['base_properties']['Expiration Date'] = $asset->expiration->date;
$asset_attributes['base_properties']['Expiration Notes'] = $asset->expiration->notes;
}
if (!empty($asset->xmp_metadata)) {
foreach ($asset->xmp_metadata as $metadata) {
$asset_attributes['additional_metadata'][$metadata['label']] = $metadata['value'];
}
}
$asset_preview = $asset->thumbnailurls[3]->url;
$subscription_details = $this->acquiadam
->getAccountSubscriptionDetails();
$dam_url = $subscription_details->url;
return [
'#theme' => 'asset_details',
'#asset_data' => $asset_attributes,
'#asset_preview' => $asset_preview,
'#asset_link' => "https://{$dam_url}/cloud/#asset/{$assetId}",
'#attached' => [
'library' => [
'media_acquiadam/asset_details',
],
],
];
}
}