You are here

class AcquiadamController in Media: Acquia DAM 8

Controller routines for Acquia DAM routes.

Hierarchy

Expanded class hierarchy of AcquiadamController

File

src/Controller/AcquiadamController.php, line 12

Namespace

Drupal\media_acquiadam\Controller
View 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

Namesort descending Modifiers Type Description Overrides
AcquiadamController::$acquiadam protected property A configured API object.
AcquiadamController::$asset protected property The asset that we're going to render details for.
AcquiadamController::assetDetailsPage public function Render a page that includes details about an asset.
AcquiadamController::assetDetailsPageTitle public function Sets the asset details page title.
AcquiadamController::create public static function Instantiates a new instance of this class. Overrides ControllerBase::create
AcquiadamController::getAsset protected function Get an asset.
AcquiadamController::__construct public function AcquiadamController constructor.
ControllerBase::$configFactory protected property The configuration factory.
ControllerBase::$currentUser protected property The current user service. 1
ControllerBase::$entityFormBuilder protected property The entity form builder.
ControllerBase::$entityManager protected property The entity manager.
ControllerBase::$entityTypeManager protected property The entity type manager.
ControllerBase::$formBuilder protected property The form builder. 2
ControllerBase::$keyValue protected property The key-value storage. 1
ControllerBase::$languageManager protected property The language manager. 1
ControllerBase::$moduleHandler protected property The module handler. 2
ControllerBase::$stateService protected property The state service.
ControllerBase::cache protected function Returns the requested cache bin.
ControllerBase::config protected function Retrieves a configuration object.
ControllerBase::container private function Returns the service container.
ControllerBase::currentUser protected function Returns the current user. 1
ControllerBase::entityFormBuilder protected function Retrieves the entity form builder.
ControllerBase::entityManager Deprecated protected function Retrieves the entity manager service.
ControllerBase::entityTypeManager protected function Retrieves the entity type manager.
ControllerBase::formBuilder protected function Returns the form builder service. 2
ControllerBase::keyValue protected function Returns a key/value storage collection. 1
ControllerBase::languageManager protected function Returns the language manager service. 1
ControllerBase::moduleHandler protected function Returns the module handler. 2
ControllerBase::redirect protected function Returns a redirect response object for the specified route. Overrides UrlGeneratorTrait::redirect
ControllerBase::state protected function Returns the state storage service.
LinkGeneratorTrait::$linkGenerator protected property The link generator. 1
LinkGeneratorTrait::getLinkGenerator Deprecated protected function Returns the link generator.
LinkGeneratorTrait::l Deprecated protected function Renders a link to a route given a route name and its parameters.
LinkGeneratorTrait::setLinkGenerator Deprecated public function Sets the link generator service.
LoggerChannelTrait::$loggerFactory protected property The logger channel factory service.
LoggerChannelTrait::getLogger protected function Gets the logger for a specific channel.
LoggerChannelTrait::setLoggerFactory public function Injects the logger channel factory.
MessengerTrait::$messenger protected property The messenger. 29
MessengerTrait::messenger public function Gets the messenger. 29
MessengerTrait::setMessenger public function Sets the messenger.
RedirectDestinationTrait::$redirectDestination protected property The redirect destination service. 1
RedirectDestinationTrait::getDestinationArray protected function Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url.
RedirectDestinationTrait::getRedirectDestination protected function Returns the redirect destination service.
RedirectDestinationTrait::setRedirectDestination public function Sets the redirect destination service.
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.
UrlGeneratorTrait::$urlGenerator protected property The url generator.
UrlGeneratorTrait::getUrlGenerator Deprecated protected function Returns the URL generator service.
UrlGeneratorTrait::setUrlGenerator Deprecated public function Sets the URL generator service.
UrlGeneratorTrait::url Deprecated protected function Generates a URL or path for a specific route based on the given parameters.