Skip to content

Commit 8393da1

Browse files
Merge pull request #382 from magento-cia/cia-2.4.8-beta2-develop-2.4-develop-sync-11232024
Cia 2.4.8 beta2 develop 2.4 develop sync 11232024
2 parents 1587588 + 8849009 commit 8393da1

File tree

40 files changed

+810
-103
lines changed

40 files changed

+810
-103
lines changed

app/code/Magento/AwsS3PageBuilder/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"description": "Aws S3 Page Builder module",
44
"require": {
55
"magento/framework": "*",
6-
"php": "~8.1.0||~8.2.0||~8.3.0"
6+
"php": "~8.2.0||~8.3.0"
77
},
88
"suggest": {
99
"magento/module-page-builder": "*",

app/code/Magento/CatalogPageBuilderAnalytics/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"magento/module-page-builder-analytics": "*",
99
"magento/module-catalog": "*",
1010
"magento/framework": "*",
11-
"php": "~8.1.0||~8.2.0||~8.3.0"
11+
"php": "~8.2.0||~8.3.0"
1212
},
1313
"type": "magento2-module",
1414
"license": [

app/code/Magento/CmsPageBuilderAnalytics/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"magento/module-page-builder-analytics": "*",
99
"magento/module-cms": "*",
1010
"magento/framework": "*",
11-
"php": "~8.1.0||~8.2.0||~8.3.0"
11+
"php": "~8.2.0||~8.3.0"
1212
},
1313
"type": "magento2-module",
1414
"license": [

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

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,40 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2019 Adobe
4+
* All Rights Reserved.
55
*/
66

77
declare(strict_types=1);
88

99
namespace Magento\PageBuilder\Controller\Adminhtml\Template;
1010

11+
use function preg_replace;
12+
use function str_replace;
13+
use function strpos;
14+
use function strtolower;
15+
use function substr;
16+
use function uniqid;
17+
use Exception;
1118
use Magento\Backend\App\Action;
1219
use Magento\Backend\App\Action\Context;
1320
use Magento\Framework\Api\ImageContent;
1421
use Magento\Framework\Api\ImageContentFactory;
1522
use Magento\Framework\Api\ImageContentValidator;
1623
use Magento\Framework\Api\SearchCriteriaBuilder;
1724
use Magento\Framework\App\Action\HttpPostActionInterface;
25+
use Magento\Framework\App\Filesystem\DirectoryList;
1826
use Magento\Framework\App\RequestInterface;
1927
use Magento\Framework\Controller\ResultFactory;
28+
use Magento\Framework\Exception\FileSystemException;
29+
use Magento\Framework\Exception\InputException;
2030
use Magento\Framework\Exception\LocalizedException;
2131
use Magento\Framework\Filesystem;
32+
use Magento\Framework\Image\AdapterFactory;
2233
use Magento\MediaStorage\Helper\File\Storage\Database;
2334
use Magento\PageBuilder\Api\Data\TemplateInterface;
2435
use Magento\PageBuilder\Api\TemplateRepositoryInterface;
2536
use Magento\PageBuilder\Model\TemplateFactory;
2637
use Psr\Log\LoggerInterface;
27-
use Magento\Framework\Image\AdapterFactory;
2838

2939
/**
3040
* Save a template within template manager
@@ -33,7 +43,7 @@
3343
*/
3444
class Save extends Action implements HttpPostActionInterface
3545
{
36-
const ADMIN_RESOURCE = 'Magento_PageBuilder::template_save';
46+
public const ADMIN_RESOURCE = 'Magento_PageBuilder::template_save';
3747

3848
/**
3949
* @var LoggerInterface
@@ -151,7 +161,7 @@ public function execute()
151161
$filePath = $this->storePreviewImage($request);
152162
// Store the preview image within the new entity
153163
$template->setPreviewImage($filePath);
154-
} catch (\Exception $e) {
164+
} catch (Exception $e) {
155165
$this->logger->critical($e);
156166

157167
return $this->resultFactory->create(ResultFactory::TYPE_JSON)->setData(
@@ -176,7 +186,7 @@ public function execute()
176186
'status' => 'error',
177187
'message' => $e->getMessage()
178188
];
179-
} catch (\Exception $e) {
189+
} catch (Exception $e) {
180190
$this->logger->critical($e);
181191

182192
$result = [
@@ -215,26 +225,28 @@ private function validate(RequestInterface $request)
215225
* Handle storing the preview image
216226
*
217227
* @param RequestInterface $request
218-
* @return string
228+
* @return null|string
229+
* @throws Exception
230+
* @throws FileSystemException
231+
* @throws InputException
219232
* @throws LocalizedException
220-
* @throws \Magento\Framework\Exception\FileSystemException
221-
* @throws \Magento\Framework\Exception\InputException
222233
*/
223-
private function storePreviewImage(RequestInterface $request) : ?string
234+
private function storePreviewImage(RequestInterface $request): ?string
224235
{
225236
$fileName = preg_replace("/[^A-Za-z0-9]/", '', str_replace(
226-
' ',
227-
'-',
228-
strtolower($request->getParam(TemplateInterface::KEY_NAME))
229-
)) . uniqid() . '.jpg';
237+
' ',
238+
'-',
239+
strtolower($request->getParam(TemplateInterface::KEY_NAME))
240+
)) . uniqid() . '.jpg';
230241

231242
// Prepare the image data
232243
$imgData = str_replace(' ', '+', $request->getParam('previewImage'));
233-
$imgData = substr($imgData, strpos($imgData, ",") + 1);
234-
// phpcs:ignore
244+
$imgData = substr($imgData, strpos($imgData, ',') + 1);
245+
// phpcs:ignore Magento2.Functions.DiscouragedFunction
235246
$decodedImage = base64_decode($imgData);
236247

237248
$imageProperties = getimagesizefromstring($decodedImage);
249+
238250
if (!$imageProperties) {
239251
throw new LocalizedException(__('Unable to get properties from image.'));
240252
}
@@ -246,16 +258,16 @@ private function storePreviewImage(RequestInterface $request) : ?string
246258
$imageContent->setType($imageProperties['mime']);
247259

248260
if ($this->imageContentValidator->isValid($imageContent)) {
249-
$mediaDirWrite = $this->filesystem
250-
->getDirectoryWrite(\Magento\Framework\App\Filesystem\DirectoryList::MEDIA);
261+
$mediaDirWrite = $this->filesystem->getDirectoryWrite(DirectoryList::MEDIA);
251262
$directory = $mediaDirWrite->getAbsolutePath('.template-manager');
252263
$mediaDirWrite->create($directory);
253-
$fileAbsolutePath = $directory . $fileName;
264+
265+
$fileAbsolutePath = $directory . DIRECTORY_SEPARATOR . $fileName;
254266
// Write the file to the directory
255267
$mediaDirWrite->getDriver()->filePutContents($fileAbsolutePath, $decodedImage);
256268
// Generate a thumbnail, called -thumb next to the image for usage in the grid
257269
$thumbPath = str_replace('.jpg', '-thumb.jpg', $fileName);
258-
$thumbAbsolutePath = $directory . $thumbPath;
270+
$thumbAbsolutePath = $directory . DIRECTORY_SEPARATOR . $thumbPath;
259271
$imageFactory = $this->imageAdapterFactory->create();
260272
$imageFactory->open($fileAbsolutePath);
261273
$imageFactory->resize(350);

app/code/Magento/PageBuilder/Model/Stage/HtmlFilter.php

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
3+
* Copyright 2024 Adobe
4+
* All rights reserved.
45
* See COPYING.txt for license details.
56
*/
67

@@ -78,17 +79,43 @@ public function filterHtml(string $content): string
7879
);
7980
foreach ($htmlContentTypes as $htmlContentType) {
8081
/* @var \DOMElement $htmlContentType */
81-
$innerHTML = '';
82-
$children = $htmlContentType->childNodes;
83-
foreach ($children as $child) {
84-
$innerHTML .= $child->ownerDocument->saveXML($child);
85-
}
8682
$htmlContentType->setAttribute(
8783
"class",
8884
$htmlContentType->getAttribute("class") . " placeholder-html-code"
8985
);
86+
87+
$innerHTML = $this->getChildrenInnerHtml($htmlContentType);
88+
9089
$htmlContentType->nodeValue = htmlentities($innerHTML);
9190
}
9291
return substr(trim($dom->saveHTML()), 5, -6);
9392
}
93+
94+
/**
95+
* Get inner HTML of element's children
96+
*
97+
* @param \DOMElement $element
98+
* @return string
99+
*/
100+
private function getChildrenInnerHtml(\DOMElement $element): string
101+
{
102+
$innerHTML = '';
103+
$childrenIterator = $element->childNodes->getIterator();
104+
while ($childrenIterator->valid()) {
105+
$child = $childrenIterator->current();
106+
try {
107+
$ownerDocument = $child->ownerDocument;
108+
} catch (\Error $error) {
109+
$ownerDocument = null;
110+
$this->loggerInterface->critical($error->getMessage());
111+
}
112+
if ($ownerDocument === null) {
113+
$childrenIterator->next();
114+
continue;
115+
}
116+
$innerHTML .= $ownerDocument->saveXML($child);
117+
$childrenIterator->next();
118+
}
119+
return $innerHTML;
120+
}
94121
}

app/code/Magento/PageBuilder/Model/TemplateRepository.php

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2019 Adobe
4+
* All Rights Reserved.
55
*/
6-
76
declare(strict_types=1);
87

98
namespace Magento\PageBuilder\Model;
109

1110
use Magento\Framework\Api\SearchCriteria\CollectionProcessorInterface;
1211
use Magento\Framework\Api\SearchCriteriaInterface;
12+
use Magento\Framework\App\Filesystem\DirectoryList;
1313
use Magento\Framework\Exception\CouldNotDeleteException;
1414
use Magento\Framework\Exception\CouldNotSaveException;
15+
use Magento\Framework\Exception\FileSystemException;
1516
use Magento\Framework\Exception\NoSuchEntityException;
1617
use Magento\Framework\Filesystem;
18+
use Magento\Framework\Image\Factory;
1719
use Magento\PageBuilder\Api\Data\TemplateInterface;
1820
use Magento\PageBuilder\Api\Data\TemplateSearchResultsInterfaceFactory;
1921
use Magento\PageBuilder\Api\TemplateRepositoryInterface;
@@ -71,6 +73,7 @@ class TemplateRepository implements TemplateRepositoryInterface
7173
* @param CollectionProcessorInterface $collectionProcessor
7274
* @param Filesystem $filesystem
7375
* @param Database $mediaStorage
76+
* @param Factory $imageFactory
7477
*/
7578
public function __construct(
7679
ResourceTemplate $resource,
@@ -79,7 +82,8 @@ public function __construct(
7982
TemplateSearchResultsInterfaceFactory $searchResultsFactory,
8083
CollectionProcessorInterface $collectionProcessor,
8184
Filesystem $filesystem,
82-
Database $mediaStorage
85+
Database $mediaStorage,
86+
private readonly Factory $imageFactory
8387
) {
8488
$this->resource = $resource;
8589
$this->templateFactory = $templateFactory;
@@ -142,25 +146,14 @@ public function getList(SearchCriteriaInterface $criteria)
142146
*/
143147
public function delete(TemplateInterface $template) : bool
144148
{
145-
$mediaDir = $this->filesystem
146-
->getDirectoryWrite(\Magento\Framework\App\Filesystem\DirectoryList::MEDIA);
147-
148149
try {
149150
$templateModel = $this->templateFactory->create();
150151
$this->resource->load($templateModel, $template->getTemplateId());
151152
$this->resource->delete($templateModel);
152153
$previewImage = $template->getPreviewImage();
153154
$previewThumbImage = $templateModel->getPreviewThumbnailImage();
154-
155-
// Remove the preview image from the media directory
156-
if ($mediaDir->isExist($previewImage)) {
157-
$mediaDir->delete($previewImage);
158-
}
159-
if ($mediaDir->isExist($previewThumbImage)) {
160-
$mediaDir->delete($previewThumbImage);
161-
}
162-
$this->mediaStorage->deleteFile($previewImage);
163-
$this->mediaStorage->deleteFile($previewThumbImage);
155+
$this->deletePreviewImage($previewImage);
156+
$this->deletePreviewImage($previewThumbImage);
164157
} catch (\Exception $exception) {
165158
throw new CouldNotDeleteException(
166159
__('Could not delete the Template: %1', $exception->getMessage())
@@ -170,6 +163,32 @@ public function delete(TemplateInterface $template) : bool
170163
return true;
171164
}
172165

166+
/**
167+
* Checks if preview image is valid and tries to delete it
168+
*
169+
* @param string $imageName
170+
* @return void
171+
* @throws FileSystemException
172+
*/
173+
private function deletePreviewImage(string $imageName): void
174+
{
175+
$isValid = true;
176+
$mediaDir = $this->filesystem
177+
->getDirectoryWrite(DirectoryList::MEDIA);
178+
179+
try {
180+
$this->imageFactory->create($mediaDir->getAbsolutePath().$imageName);
181+
} catch (\Exception) {
182+
$isValid = false;
183+
}
184+
185+
if ($mediaDir->isExist($imageName) && $isValid) {
186+
$mediaDir->delete($imageName);
187+
}
188+
189+
$this->mediaStorage->deleteFile($imageName);
190+
}
191+
173192
/**
174193
* @inheritdoc
175194
*/

app/code/Magento/PageBuilder/Model/Wysiwyg/DefaultConfigProvider.php

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,34 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2018 Adobe
4+
* All Rights Reserved.
55
*/
66
declare(strict_types=1);
77

88
namespace Magento\PageBuilder\Model\Wysiwyg;
99

10+
use Magento\Framework\DataObject;
11+
use Magento\Framework\View\Asset\Repository;
12+
1013
/**
1114
* This DefaultConfigProvider overrides existing configuration provided from the cms module
1215
*/
1316
class DefaultConfigProvider implements \Magento\Framework\Data\Wysiwyg\ConfigProviderInterface
1417
{
1518
/**
16-
* @var \Magento\Framework\View\Asset\Repository
19+
* @var Repository
1720
*/
18-
private $assetRepo;
21+
private Repository $assetRepo;
1922
/**
2023
* @var array
2124
*/
2225
private $additionalSettings;
2326
/**
24-
* @param \Magento\Framework\View\Asset\Repository $assetRepo
27+
* @param Repository $assetRepo
2528
* @param array $additionalSettings
2629
*/
2730
public function __construct(
28-
\Magento\Framework\View\Asset\Repository $assetRepo,
31+
Repository $assetRepo,
2932
array $additionalSettings
3033
) {
3134
$this->assetRepo = $assetRepo;
@@ -34,15 +37,15 @@ public function __construct(
3437
/**
3538
* Returns configuration data
3639
*
37-
* @param \Magento\Framework\DataObject $config
38-
* @return \Magento\Framework\DataObject
40+
* @param DataObject $config
41+
* @return DataObject
3942
*/
40-
public function getConfig(\Magento\Framework\DataObject $config): \Magento\Framework\DataObject
43+
public function getConfig(DataObject $config): DataObject
4144
{
4245
$config->addData(
4346
[
4447
'tinymce' => [
45-
'toolbar' => 'undo redo | styles | fontsizeselect | lineheight | forecolor backcolor ' .
48+
'toolbar' => 'undo redo | styles | fontfamily fontsize | lineheight | forecolor backcolor ' .
4649
'| bold italic underline | alignleft aligncenter alignright | numlist bullist ' .
4750
'| link image table charmap',
4851

0 commit comments

Comments
 (0)