/** * @param MediaInterface $media * @param string $format * * @return string */ public function getMediaFormatUrl(MediaInterface $media, $format) { $key = $media->getFilesystemName(); if ($format != '' && MediaInterface::MEDIA_ORIGINAL != $format) { $key = $media->getAlternative($format); } return $this->getFileUrl($key); }
/** * 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); }