You are here

public function FileMetadataPluginBase::getMetadata in File metadata manager 8.2

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

Gets a metadata element.

Parameters

mixed|null $key: A key to determine the metadata element to be returned. If NULL, the entire metadata will be returned.

Return value

mixed The value of the element specified by $key. If $key is NULL, the entire metadata.

Overrides FileMetadataPluginInterface::getMetadata

2 calls to FileMetadataPluginBase::getMetadata()
FileMetadataPluginBase::removeMetadata in src/Plugin/FileMetadata/FileMetadataPluginBase.php
Removes a metadata element.
FileMetadataPluginBase::setMetadata in src/Plugin/FileMetadata/FileMetadataPluginBase.php
Sets a metadata element.

File

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

Class

FileMetadataPluginBase
Abstract implementation of a base File Metadata plugin.

Namespace

Drupal\file_mdm\Plugin\FileMetadata

Code

public function getMetadata($key = NULL) {
  if (!$this
    ->getUri()) {
    throw new FileMetadataException("No URI specified", $this
      ->getPluginId(), __FUNCTION__);
  }
  if (!$this->hash) {
    throw new FileMetadataException("No hash specified", $this
      ->getPluginId(), __FUNCTION__);
  }
  if ($this->metadata === NULL) {

    // Metadata has not been loaded yet. Try loading it from cache first.
    $this
      ->loadMetadataFromCache();
  }
  if ($this->metadata === NULL && $this->isMetadataLoaded !== FileMetadataInterface::LOADED_FROM_FILE) {

    // Metadata has not been loaded yet. Try loading it from file if URI is
    // defined and a read attempt was not made yet.
    $this
      ->loadMetadataFromFile();
  }
  return $this
    ->doGetMetadata($key);
}