You are here

public function MediaEntityHelper::getExistingFile in Media: Acquia DAM 8

Attempts to load an existing file entity from the given media entity.

Return value

\Drupal\file\FileInterface|false A loaded file entity or FALSE if none could be found.

1 call to MediaEntityHelper::getExistingFile()
MediaEntityHelper::getFile in src/MediaEntityHelper.php
Returns an associated file or creates a new one.

File

src/MediaEntityHelper.php, line 113

Class

MediaEntityHelper
Class MediaEntityHelper.

Namespace

Drupal\media_acquiadam

Code

public function getExistingFile() {
  try {
    if ($fid = $this
      ->getExistingFileId()) {

      /** @var \Drupal\file\FileInterface $file */
      $file = $this->entityTypeManager
        ->getStorage('file')
        ->load($fid);
    }
  } catch (\Exception $x) {
    $file = FALSE;
  }
  return !empty($file) ? $file : FALSE;
}