You are here

public function FileMetadataPluginBase::setMetadata 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::setMetadata()

Sets a metadata element.

Parameters

mixed $key: A key to determine the metadata element to be changed.

mixed $value: The value to change the metadata element to.

Return value

bool TRUE if metadata was changed successfully, FALSE otherwise.

Overrides FileMetadataPluginInterface::setMetadata

File

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

Class

FileMetadataPluginBase
Abstract implementation of a base File Metadata plugin.

Namespace

Drupal\file_mdm\Plugin\FileMetadata

Code

public function setMetadata($key, $value) {
  if ($key === NULL) {
    throw new FileMetadataException("No metadata key specified for file at '{$this->getUri()}'", $this
      ->getPluginId(), __FUNCTION__);
  }
  if (!$this->metadata && !$this
    ->getMetadata()) {
    throw new FileMetadataException("No metadata loaded for file at '{$this->getUri()}'", $this
      ->getPluginId(), __FUNCTION__);
  }
  if ($this
    ->doSetMetadata($key, $value)) {
    $this->hasMetadataChangedFromFileVersion = TRUE;
    if ($this->isMetadataLoaded === FileMetadataInterface::LOADED_FROM_CACHE) {
      $this->hasMetadataChangedFromCacheVersion = TRUE;
    }
    return TRUE;
  }
  return FALSE;
}