You are here

function media_acquiadam_create_file_from_asset in Media: Acquia DAM 7

Create a local file entity for an Acquia DAM asset.

Parameters

AcquiaDAM_Assets_Asset $asset: The Acquia DAM asset to create a file entity for.

bool $ignoreExisting: By default we return an existing file if one was found. Set this TRUE to force a new file to be created.

Return value

object|bool The created file entity or FALSE on failure.

1 call to media_acquiadam_create_file_from_asset()
media_acquiadam_browser_choose_asset_form_save_assets in modules/media_acquiadam_browser/includes/media_acquiadam_browser.forms.inc
Create Drupal file entities given an array of asset IDs.

File

includes/media_acquiadam.helpers.inc, line 20
Helper functions for working with Acquia DAM within Drupal.

Code

function media_acquiadam_create_file_from_asset(AcquiaDAM_Assets_Asset $asset, $ignoreExisting = FALSE) {
  global $user;
  if (!$asset instanceof AcquiaDAM_Assets_Asset) {
    return FALSE;
  }
  $uri = media_acquiadam_asset_to_uri($asset);

  // Reuse an existing file whenever possible.
  $file = file_uri_to_object($uri, TRUE);

  // We got a file object for a new file instead of an existing one.
  if (!empty($file) && empty($file->fid)) {
    media_acquiadam_cache_set($asset);
    $file->filename = drupal_basename($asset['name']);
    $file->acquiadam_id = $asset['id'];
    file_save($file);
  }
  return empty($file->fid) ? FALSE : $file;
}