You are here

public function AcquiaDAM_Assets_AbstractAsset::getThumbnailUrl in Media: Acquia DAM 7

Get the URL to the DAM-provided thumbnail if possible.

Parameters

int $thumbnailSize: Find the closest thumbnail size without going over when multiple thumbnails are available.

Return value

string|false The preview URL or FALSE if none available.

1 call to AcquiaDAM_Assets_AbstractAsset::getThumbnailUrl()
AcquiaDAM_Assets_AbstractAsset::getPreviewUrl in src/AcquiaDAM/AcquiaDAM_Assets_AbstractAsset.inc
Get the URL to the DAM-provided preview if possible.

File

src/AcquiaDAM/AcquiaDAM_Assets_AbstractAsset.inc, line 253

Class

AcquiaDAM_Assets_AbstractAsset
Abstract class base for Acquia DAM assets.

Code

public function getThumbnailUrl($thumbnailSize = 1280) {
  $this
    ->get();
  if (!empty($this->asset['thumbnailurls'][0]['url'])) {

    // Copy thumbnail array to variable to avoid a notice about indirect
    // access.
    $thumbnails = $this->asset['thumbnailurls'];

    // Default to first regardless of size.
    $biggest_matching = $thumbnails[0]['url'];
    foreach ($thumbnails as $tn) {
      if (!empty($tn['url']) && $thumbnailSize >= $tn['size']) {

        // Certain types do not have a 1280 size available despite returning
        // an URL. We either have to hard code mime types as they crop up, or
        // check if the URL is accessible on our own. Other URL sizes do not
        // appear to have this issue.
        if (1280 == $tn['size']) {
          $result = drupal_http_request($tn['url'], [
            'method' => 'HEAD',
          ]);
          if (403 == $result->code) {
            continue;
          }
        }
        $biggest_matching = $tn['url'];
      }
    }
    return $biggest_matching;
  }
  return FALSE;
}