/** * Override the file alternative for $media with $newFile and run it * * @param MediaInterface $media * @param string $newFilePath * @param string $formatName */ public function overrideAlternative(MediaInterface $media, $newFilePath, $formatName) { $alternativeName = $media->getAlternative($formatName); $this->deleteFile($alternativeName); $newFilename = basename($newFilePath); $newAlternativeName = $this->generateAlternativeName($formatName, $newFilename); $this->mediaStorageManager->uploadFile($newAlternativeName, $newFilePath); $media->addAlternative($formatName, $newAlternativeName); }