You are here

public function FileMetadata::getMetadata in File metadata manager 8

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

Gets a metadata element.

Parameters

string $metadata_id: The id of the FileMetadata plugin.

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 FileMetadataInterface::getMetadata

File

src/FileMetadata.php, line 180

Class

FileMetadata
A file metadata object.

Namespace

Drupal\file_mdm

Code

public function getMetadata($metadata_id, $key = NULL) {
  try {
    if ($plugin = $this
      ->getFileMetadataPlugin($metadata_id)) {
      $metadata = $plugin
        ->getMetadata($key);
    }
    else {
      $metadata = NULL;
    }
  } catch (\Exception $e) {
    $this->logger
      ->error($e
      ->getMessage());
    $metadata = NULL;
  }
  return $metadata;
}