You are here

public function FileMetadataPluginBase::loadMetadataFromFile in File metadata manager 8

Same name and namespace in other branches
  1. 8.2 src/Plugin/FileMetadata/FileMetadataPluginBase.php \Drupal\file_mdm\Plugin\FileMetadata\FileMetadataPluginBase::loadMetadataFromFile()

Loads file metadata from the file at URI/local path.

Return value

bool TRUE if metadata was loaded successfully, FALSE otherwise.

Throws

\Drupal\file_mdm\FileMetadataException In case there were significant errors reading from file.

Overrides FileMetadataPluginInterface::loadMetadataFromFile

1 call to FileMetadataPluginBase::loadMetadataFromFile()
FileMetadataPluginBase::getMetadata in src/Plugin/FileMetadata/FileMetadataPluginBase.php
Gets a metadata element.

File

src/Plugin/FileMetadata/FileMetadataPluginBase.php, line 274

Class

FileMetadataPluginBase
Abstract implementation of a base File Metadata plugin.

Namespace

Drupal\file_mdm\Plugin\FileMetadata

Code

public function loadMetadataFromFile() {
  if (!file_exists($this
    ->getLocalTempPath())) {

    // File does not exists.
    throw new FileMetadataException("File at '{$this->getLocalTempPath()}' does not exist", $this
      ->getPluginId(), __FUNCTION__);
  }
  $this->hasMetadataChangedFromFileVersion = FALSE;
  if (($this->metadata = $this
    ->doGetMetadataFromFile()) === NULL) {
    $this->isMetadataLoaded = FileMetadataInterface::NOT_LOADED;
    $this
      ->deleteCachedMetadata();
  }
  else {
    $this->isMetadataLoaded = FileMetadataInterface::LOADED_FROM_FILE;
    $this
      ->saveMetadataToCache();
  }
  return (bool) $this->metadata;
}