Skip to content

Commit a5a0462

Browse files
committed
MC-38246: Support by Magento Page Builder
1 parent 5acfe6c commit a5a0462

File tree

1 file changed

+12
-11
lines changed
  • app/code/Magento/PageBuilder/Controller/Adminhtml/Template

1 file changed

+12
-11
lines changed

app/code/Magento/PageBuilder/Controller/Adminhtml/Template/Save.php

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -222,14 +222,11 @@ private function validate(RequestInterface $request)
222222
*/
223223
private function storePreviewImage(RequestInterface $request) : ?string
224224
{
225-
$mediaDir = $this->filesystem
226-
->getDirectoryWrite(\Magento\Framework\App\Filesystem\DirectoryList::MEDIA);
227225
$fileName = preg_replace("/[^A-Za-z0-9]/", '', str_replace(
228226
' ',
229227
'-',
230228
strtolower($request->getParam(TemplateInterface::KEY_NAME))
231229
)) . uniqid() . '.jpg';
232-
$filePath = '.template-manager' . DIRECTORY_SEPARATOR . $fileName;
233230

234231
// Prepare the image data
235232
$imgData = str_replace(' ', '+', $request->getParam('previewImage'));
@@ -249,21 +246,25 @@ private function storePreviewImage(RequestInterface $request) : ?string
249246
$imageContent->setType($imageProperties['mime']);
250247

251248
if ($this->imageContentValidator->isValid($imageContent)) {
252-
$absolutePath = $mediaDir->getAbsolutePath() . $filePath;
249+
$mediaDirWrite = $this->filesystem
250+
->getDirectoryWrite(\Magento\Framework\App\Filesystem\DirectoryList::MEDIA);
251+
$directory = $mediaDirWrite->getAbsolutePath('.template-manager');
252+
$mediaDirWrite->create($directory);
253+
$fileAbsolutePath = $directory . $fileName;
253254
// Write the file to the directory
254-
$mediaDir->getDriver()->filePutContents($absolutePath, $decodedImage);
255+
$mediaDirWrite->getDriver()->filePutContents($fileAbsolutePath, $decodedImage);
255256
// Generate a thumbnail, called -thumb next to the image for usage in the grid
256-
$thumbPath = str_replace('.jpg', '-thumb.jpg', $filePath);
257-
$thumbAbsolutePath = $mediaDir->getAbsolutePath() . $thumbPath;
257+
$thumbPath = str_replace('.jpg', '-thumb.jpg', $fileName);
258+
$thumbAbsolutePath = $directory . $thumbPath;
258259
$imageFactory = $this->imageAdapterFactory->create();
259-
$imageFactory->open($absolutePath);
260+
$imageFactory->open($fileAbsolutePath);
260261
$imageFactory->resize(350);
261262
$imageFactory->save($thumbAbsolutePath);
262-
$this->mediaStorage->saveFile($filePath);
263-
$this->mediaStorage->saveFile($thumbPath);
263+
$this->mediaStorage->saveFile($fileAbsolutePath);
264+
$this->mediaStorage->saveFile($thumbAbsolutePath);
264265

265266
// Store the preview image within the new entity
266-
return $filePath;
267+
return $mediaDirWrite->getRelativePath($fileAbsolutePath);
267268
}
268269

269270
return null;

0 commit comments

Comments
 (0)