You are here

public function AcquiadamController::assetDetailsPage in Media: Acquia DAM 8

Render a page that includes details about an asset.

Parameters

int $assetId: The asset ID to retrieve data for.

Return value

array A render array.

File

src/Controller/AcquiadamController.php, line 88

Class

AcquiadamController
Controller routines for Acquia DAM routes.

Namespace

Drupal\media_acquiadam\Controller

Code

public function assetDetailsPage($assetId) {

  // Get the asset.
  // @todo Catch exceptions here and do the right thing.
  $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'];
    }
  }

  // Get an asset preview.
  $asset_preview = $asset->thumbnailurls[3]->url;

  // Get subscription details so that we can generate the correct URL to send
  // the user to the DAM UI.
  $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',
      ],
    ],
  ];
}