You are here

function media_acquiadam_url_inbound_alter in Media: Acquia DAM 7

Implements hook_url_inbound_alter().

File

./media_acquiadam.module, line 91

Code

function media_acquiadam_url_inbound_alter(&$path, $original_path, $path_language) {

  // Hijack the normal image style path and redirect it to our custom handler
  // path so we can avoid having to guess asset type when delivering images.
  $directory_path = file_stream_wrapper_get_instance_by_scheme(file_default_scheme())
    ->getDirectoryPath();
  $regex = preg_quote($directory_path) . '\\/styles\\/(\\w+?)\\/acquiadam\\/(\\d+)\\.\\w+';
  if (preg_match("|^{$regex}|", $original_path, $matches)) {

    // Folders do not normally trigger image style creation and should be styled
    // with theme('image_style', ...) directly. We can safely hard-code the
    // asset type here.
    $path = vsprintf('%s/styles/%s/acquiadam/asset/%d', [
      $directory_path,
      $matches[1],
      $matches[2],
    ]);
  }
}