Skip to content

Commit 915ffe8

Browse files
Merge branch '2.4-develop' into GL_PR_Arrows_July_03_2024
2 parents f204e25 + 0c53bbf commit 915ffe8

File tree

30 files changed

+783
-258
lines changed

30 files changed

+783
-258
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
/**
3+
* Copyright 2024 Adobe
4+
* All Rights Reserved.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Backend\ViewModel;
9+
10+
/**
11+
* View model interface for requirejs configuration modifier
12+
*/
13+
interface RequireJsConfigModifierInterface
14+
{
15+
/**
16+
* Modifies requirejs configuration
17+
*
18+
* @param array $config requirejs configuration
19+
* @return array
20+
*/
21+
public function modify(array $config): array;
22+
}

app/code/Magento/Backend/view/adminhtml/templates/page/js/require_js.phtml

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,20 @@
55
*/
66

77
/** @var \Magento\Framework\View\Helper\SecureHtmlRenderer $secureRenderer */
8+
/** @var \Magento\Backend\Block\Page\RequireJs $block */
9+
10+
$requireJsConfig = [
11+
'baseUrl' => $block->getViewFileUrl('/'),
12+
];
13+
14+
$configModifier = $block->getConfigModifier();
15+
$requireJsConfig = $configModifier instanceof \Magento\Backend\ViewModel\RequireJsConfigModifierInterface
16+
? $configModifier->modify($requireJsConfig)
17+
: $requireJsConfig;
818

919
$scriptString = '
1020
var BASE_URL = \'' . /* @noEscape */ $block->getUrl('*') . '\';
1121
var FORM_KEY = \'' . /* @noEscape */ $block->getFormKey() . '\';
12-
var require = {
13-
\'baseUrl\': \'' . /* @noEscape */ $block->getViewFileUrl('/') . '\'
14-
};';
15-
16-
echo /* @noEscape */ $secureRenderer->renderTag('script', [], $scriptString, false);
22+
var require = ' . /* @noEscape */ json_encode($requireJsConfig) .';';
23+
?>
24+
<?= /* @noEscape */ $secureRenderer->renderTag('script', [], $scriptString, false) ?>

app/code/Magento/Catalog/Controller/Product/Compare/Index.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
*/
77
namespace Magento\Catalog\Controller\Product\Compare;
88

9-
use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface;
109
use Magento\Catalog\Api\ProductRepositoryInterface;
10+
use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface;
1111
use Magento\Framework\Data\Form\FormKey\Validator;
1212
use Magento\Framework\View\Result\PageFactory;
1313

@@ -81,6 +81,8 @@ public function execute()
8181
$this->_catalogSession->setBeforeCompareUrl(
8282
$this->urlDecoder->decode($beforeUrl)
8383
);
84+
} else {
85+
$this->_catalogSession->unsBeforeCompareUrl();
8486
}
8587
return $this->resultPageFactory->create();
8688
}

app/code/Magento/Catalog/CustomerData/CompareProducts.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Magento\Framework\App\Config\ScopeConfigInterface;
1010
use Magento\Framework\App\ObjectManager;
1111
use Magento\Framework\Exception\LocalizedException;
12+
use Magento\Framework\UrlInterface;
1213
use Magento\Store\Model\StoreManagerInterface;
1314

1415
/**
@@ -43,25 +44,33 @@ class CompareProducts implements SectionSourceInterface
4344
*/
4445
private $storeManager;
4546

47+
/**
48+
* @var UrlInterface
49+
*/
50+
private $urlBuilder;
51+
4652
/**
4753
* @param \Magento\Catalog\Helper\Product\Compare $helper
4854
* @param \Magento\Catalog\Model\Product\Url $productUrl
4955
* @param \Magento\Catalog\Helper\Output $outputHelper
5056
* @param ScopeConfigInterface|null $scopeConfig
5157
* @param StoreManagerInterface|null $storeManager
58+
* @param UrlInterface|null $urlBuilder
5259
*/
5360
public function __construct(
5461
\Magento\Catalog\Helper\Product\Compare $helper,
5562
\Magento\Catalog\Model\Product\Url $productUrl,
5663
\Magento\Catalog\Helper\Output $outputHelper,
5764
?ScopeConfigInterface $scopeConfig = null,
58-
?StoreManagerInterface $storeManager = null
65+
?StoreManagerInterface $storeManager = null,
66+
?UrlInterface $urlBuilder = null
5967
) {
6068
$this->helper = $helper;
6169
$this->productUrl = $productUrl;
6270
$this->outputHelper = $outputHelper;
6371
$this->scopeConfig = $scopeConfig ?? ObjectManager::getInstance()->get(ScopeConfigInterface::class);
6472
$this->storeManager = $storeManager ?? ObjectManager::getInstance()->get(StoreManagerInterface::class);
73+
$this->urlBuilder = $urlBuilder ?? ObjectManager::getInstance()->get(UrlInterface::class);
6574
}
6675

6776
/**
@@ -73,7 +82,7 @@ public function getSectionData()
7382
return [
7483
'count' => $count,
7584
'countCaption' => $count == 1 ? __('1 item') : __('%1 items', $count),
76-
'listUrl' => $this->helper->getListUrl(),
85+
'listUrl' => $this->urlBuilder->getUrl('catalog/product_compare/index'),
7786
'items' => $count ? $this->getItems() : [],
7887
'websiteId' => $this->storeManager->getWebsite()->getId()
7988
];

app/code/Magento/Catalog/Test/Unit/CustomerData/CompareProductsTest.php

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,15 @@
1717
use Magento\Catalog\Model\ResourceModel\Product\Compare\Item\Collection;
1818
use Magento\Framework\App\Config\ScopeConfigInterface;
1919
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
20+
use Magento\Framework\UrlInterface;
21+
use Magento\Store\Model\StoreManagerInterface;
2022
use Magento\Store\Model\Website;
2123
use PHPUnit\Framework\MockObject\MockObject;
2224
use PHPUnit\Framework\TestCase;
23-
use Magento\Store\Model\StoreManagerInterface;
2425

26+
/**
27+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
28+
*/
2529
class CompareProductsTest extends TestCase
2630
{
2731
/**
@@ -64,6 +68,11 @@ class CompareProductsTest extends TestCase
6468
*/
6569
private $websiteMock;
6670

71+
/**
72+
* @var UrlInterface|MockObject
73+
*/
74+
private $urlBuilder;
75+
6776
/**
6877
* @var array
6978
*/
@@ -88,6 +97,9 @@ protected function setUp(): void
8897
$this->scopeConfigMock = $this->getMockBuilder(ScopeConfigInterface::class)
8998
->disableOriginalConstructor()
9099
->getMockForAbstractClass();
100+
$this->urlBuilder = $this->getMockBuilder(UrlInterface::class)
101+
->disableOriginalConstructor()
102+
->getMock();
91103

92104
$this->storeManagerMock = $this->getMockBuilder(
93105
StoreManagerInterface::class
@@ -97,7 +109,7 @@ protected function setUp(): void
97109
$this->websiteMock = $this->getMockBuilder(
98110
Website::class
99111
)->onlyMethods(
100-
['getId',]
112+
['getId']
101113
)->disableOriginalConstructor()
102114
->getMock();
103115

@@ -110,8 +122,8 @@ protected function setUp(): void
110122
'productUrl' => $this->productUrlMock,
111123
'outputHelper' => $this->outputHelperMock,
112124
'scopeConfig' => $this->scopeConfigMock,
113-
'storeManager' => $this->storeManagerMock
114-
125+
'storeManager' => $this->storeManagerMock,
126+
'urlBuilder' => $this->urlBuilder
115127
]
116128
);
117129
}
@@ -219,9 +231,10 @@ public function testGetSectionData()
219231
->method('getItemCollection')
220232
->willReturn($itemCollectionMock);
221233

222-
$this->helperMock->expects($this->once())
223-
->method('getListUrl')
234+
$this->urlBuilder->expects($this->once())
235+
->method('getUrl')
224236
->willReturn('http://list.url');
237+
225238
$this->storeManagerMock->expects($this->any())->method('getWebsite')->willReturn($this->websiteMock);
226239
$this->websiteMock->expects($this->any())->method('getId')->willReturn(1);
227240
$this->assertEquals(
@@ -269,8 +282,8 @@ public function testGetSectionDataNoItems()
269282
$this->helperMock->expects($this->never())
270283
->method('getItemCollection');
271284

272-
$this->helperMock->expects($this->once())
273-
->method('getListUrl')
285+
$this->urlBuilder->expects($this->once())
286+
->method('getUrl')
274287
->willReturn('http://list.url');
275288

276289
$this->storeManagerMock->expects($this->any())->method('getWebsite')->willReturn($this->websiteMock);
@@ -314,8 +327,8 @@ public function testGetSectionDataSingleItem()
314327
->method('getItemCollection')
315328
->willReturn($itemCollectionMock);
316329

317-
$this->helperMock->expects($this->once())
318-
->method('getListUrl')
330+
$this->urlBuilder->expects($this->once())
331+
->method('getUrl')
319332
->willReturn('http://list.url');
320333

321334
$this->assertEquals(

app/code/Magento/Cms/Model/Wysiwyg/Images/Storage.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Magento\Framework\App\Config\ScopeConfigInterface;
1313
use Magento\Framework\App\Filesystem\DirectoryList;
1414
use Magento\Framework\App\ObjectManager;
15+
use Magento\Framework\Data\Collection;
1516
use Magento\Framework\Exception\LocalizedException;
1617

1718
/**
@@ -289,6 +290,7 @@ protected function createSubDirectories($path)
289290
*
290291
* @return array
291292
* @deprecated
293+
* @see isDirectoryAllowed
292294
*/
293295
protected function getConditionsForExcludeDirs()
294296
{
@@ -317,6 +319,7 @@ protected function getConditionsForExcludeDirs()
317319
* @param array $conditions
318320
* @return \Magento\Framework\Data\Collection\Filesystem
319321
* @deprecated
322+
* @see \Magento\Framework\Data\Collection\Filesystem::setDirsFilter
320323
*/
321324
protected function removeItemFromCollection($collection, $conditions)
322325
{
@@ -415,7 +418,7 @@ public function getFilesCollection($path, $type = null)
415418
$mimeType = $itemStats['mimetype'] ?? $this->mime->getMimeType($item->getFilename());
416419
$item->setMimeType($mimeType);
417420

418-
if ($this->isImage($item->getBasename())) {
421+
if ($this->isImageValid($item)) {
419422
$thumbUrl = $this->getThumbnailUrl($item->getFilename(), true);
420423
// generate thumbnail "on the fly" if it does not exists
421424
if (!$thumbUrl) {
@@ -435,6 +438,12 @@ public function getFilesCollection($path, $type = null)
435438
$this->logger->notice(sprintf("GetImageSize caused error: %s", $e->getMessage()));
436439
}
437440
} else {
441+
$this->logger->warning(
442+
sprintf(
443+
"The image %s is invalid and cannot be displayed in the gallery.",
444+
$item->getBasename()
445+
)
446+
);
438447
$thumbUrl = $this->_assetRepo->getUrl(self::THUMB_PLACEHOLDER_PATH_SUFFIX);
439448
}
440449

@@ -1058,4 +1067,15 @@ private function getAllowedDirMask(string $path)
10581067

10591068
return '/^(' . implode('|', array_unique(array_column($allowedDirs, $subfolderLevel - 1))) . ')$/';
10601069
}
1070+
1071+
/**
1072+
* Checks if the file is an image and has a size greater than 0 to validate it can be processes in the gallery.
1073+
*
1074+
* @param Collection $item
1075+
* @return bool
1076+
*/
1077+
private function isImageValid($item)
1078+
{
1079+
return $this->isImage($item->getBasename()) && $item->getSize() > 0;
1080+
}
10611081
}

0 commit comments

Comments
 (0)