You are here

protected function AssetFileEntityHelper::replaceExistingFile in Media: Acquia DAM 8

Replaces the binary contents of the given file entity.

Parameters

\Drupal\file\FileInterface $file: The file entity to replace the binary contents of.

mixed $data: The contents to save.

string $destination: The destination uri to save to.

Return value

\Drupal\file\FileInterface The file entity that was updated.

1 call to AssetFileEntityHelper::replaceExistingFile()
AssetFileEntityHelper::createNewFile in src/Service/AssetFileEntityHelper.php
Creates a new file for an asset.

File

src/Service/AssetFileEntityHelper.php, line 340

Class

AssetFileEntityHelper
Class AssetFileEntityHelper.

Namespace

Drupal\media_acquiadam\Service

Code

protected function replaceExistingFile(FileInterface $file, $data, $destination) {
  $uri = $this->fileSystem
    ->saveData($data, $destination, FileSystemInterface::EXISTS_REPLACE);
  $file
    ->setFileUri($uri);
  $file
    ->setFilename($this->fileSystem
    ->basename($destination));
  $file
    ->save();
  return $file;
}