class AcquiadamController in Media: Acquia DAM 8
Controller routines for Acquia DAM routes.
Hierarchy
- class \Drupal\Core\Controller\ControllerBase implements ContainerInjectionInterface uses LoggerChannelTrait, MessengerTrait, LinkGeneratorTrait, RedirectDestinationTrait, UrlGeneratorTrait, StringTranslationTrait- class \Drupal\media_acquiadam\Controller\AcquiadamController
 
Expanded class hierarchy of AcquiadamController
File
- src/Controller/ AcquiadamController.php, line 12 
Namespace
Drupal\media_acquiadam\ControllerView source
class AcquiadamController extends ControllerBase {
  /**
   * A configured API object.
   *
   * @var \Drupal\media_acquiadam\Acquiadam
   */
  protected $acquiadam;
  /**
   * The asset that we're going to render details for.
   *
   * @var \cweagans\webdam\Entity\Asset
   */
  protected $asset;
  /**
   * AcquiadamController constructor.
   *
   * @param \Drupal\media_acquiadam\AcquiadamInterface $acquiadam
   *   The Acquiadam Interface.
   */
  public function __construct(AcquiadamInterface $acquiadam) {
    $this->acquiadam = $acquiadam;
  }
  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container) {
    return new static($container
      ->get('media_acquiadam.acquiadam'));
  }
  /**
   * Sets the asset details page title.
   *
   * @param int $assetId
   *   The asset ID for the asset to render title for.
   *
   * @return string
   *   The asset details page title.
   */
  public function assetDetailsPageTitle($assetId) {
    $asset = $this
      ->getAsset($assetId);
    return $this
      ->t("Asset details: %filename", [
      '%filename' => $asset->filename,
    ]);
  }
  /**
   * Get an asset.
   *
   * @param int $assetId
   *   The asset ID for the asset to render details for.
   *
   * @return \cweagans\webdam\Entity\Asset|false
   *   The asset or FALSE on failure.
   */
  protected function getAsset($assetId) {
    if (!isset($this->asset)) {
      $this->asset = $this->acquiadam
        ->getAsset($assetId, TRUE);
    }
    return $this->asset;
  }
  /**
   * Render a page that includes details about an asset.
   *
   * @param int $assetId
   *   The asset ID to retrieve data for.
   *
   * @return array
   *   A render array.
   */
  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',
        ],
      ],
    ];
  }
}Members
| Name   | Modifiers | Type | Description | Overrides | 
|---|---|---|---|---|
| AcquiadamController:: | protected | property | A configured API object. | |
| AcquiadamController:: | protected | property | The asset that we're going to render details for. | |
| AcquiadamController:: | public | function | Render a page that includes details about an asset. | |
| AcquiadamController:: | public | function | Sets the asset details page title. | |
| AcquiadamController:: | public static | function | Instantiates a new instance of this class. Overrides ControllerBase:: | |
| AcquiadamController:: | protected | function | Get an asset. | |
| AcquiadamController:: | public | function | AcquiadamController constructor. | |
| ControllerBase:: | protected | property | The configuration factory. | |
| ControllerBase:: | protected | property | The current user service. | 1 | 
| ControllerBase:: | protected | property | The entity form builder. | |
| ControllerBase:: | protected | property | The entity manager. | |
| ControllerBase:: | protected | property | The entity type manager. | |
| ControllerBase:: | protected | property | The form builder. | 2 | 
| ControllerBase:: | protected | property | The key-value storage. | 1 | 
| ControllerBase:: | protected | property | The language manager. | 1 | 
| ControllerBase:: | protected | property | The module handler. | 2 | 
| ControllerBase:: | protected | property | The state service. | |
| ControllerBase:: | protected | function | Returns the requested cache bin. | |
| ControllerBase:: | protected | function | Retrieves a configuration object. | |
| ControllerBase:: | private | function | Returns the service container. | |
| ControllerBase:: | protected | function | Returns the current user. | 1 | 
| ControllerBase:: | protected | function | Retrieves the entity form builder. | |
| ControllerBase:: | protected | function | Retrieves the entity manager service. | |
| ControllerBase:: | protected | function | Retrieves the entity type manager. | |
| ControllerBase:: | protected | function | Returns the form builder service. | 2 | 
| ControllerBase:: | protected | function | Returns a key/value storage collection. | 1 | 
| ControllerBase:: | protected | function | Returns the language manager service. | 1 | 
| ControllerBase:: | protected | function | Returns the module handler. | 2 | 
| ControllerBase:: | protected | function | Returns a redirect response object for the specified route. Overrides UrlGeneratorTrait:: | |
| ControllerBase:: | protected | function | Returns the state storage service. | |
| LinkGeneratorTrait:: | protected | property | The link generator. | 1 | 
| LinkGeneratorTrait:: | protected | function | Returns the link generator. | |
| LinkGeneratorTrait:: | protected | function | Renders a link to a route given a route name and its parameters. | |
| LinkGeneratorTrait:: | public | function | Sets the link generator service. | |
| LoggerChannelTrait:: | protected | property | The logger channel factory service. | |
| LoggerChannelTrait:: | protected | function | Gets the logger for a specific channel. | |
| LoggerChannelTrait:: | public | function | Injects the logger channel factory. | |
| MessengerTrait:: | protected | property | The messenger. | 29 | 
| MessengerTrait:: | public | function | Gets the messenger. | 29 | 
| MessengerTrait:: | public | function | Sets the messenger. | |
| RedirectDestinationTrait:: | protected | property | The redirect destination service. | 1 | 
| RedirectDestinationTrait:: | protected | function | Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url. | |
| RedirectDestinationTrait:: | protected | function | Returns the redirect destination service. | |
| RedirectDestinationTrait:: | public | function | Sets the redirect destination service. | |
| StringTranslationTrait:: | protected | property | The string translation service. | 1 | 
| StringTranslationTrait:: | protected | function | Formats a string containing a count of items. | |
| StringTranslationTrait:: | protected | function | Returns the number of plurals supported by a given language. | |
| StringTranslationTrait:: | protected | function | Gets the string translation service. | |
| StringTranslationTrait:: | public | function | Sets the string translation service to use. | 2 | 
| StringTranslationTrait:: | protected | function | Translates a string to the current language or to a given language. | |
| UrlGeneratorTrait:: | protected | property | The url generator. | |
| UrlGeneratorTrait:: | protected | function | Returns the URL generator service. | |
| UrlGeneratorTrait:: | public | function | Sets the URL generator service. | |
| UrlGeneratorTrait:: | protected | function | Generates a URL or path for a specific route based on the given parameters. | 
