Skip to content

Commit 361a16a

Browse files
Merge branch '2.4.4-develop' into 2.4.4-develop-2.4-develop-sync-111021
2 parents ca1b5b6 + 517fad6 commit 361a16a

File tree

18 files changed

+403
-22
lines changed

18 files changed

+403
-22
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Contact\Plugin\UserDataProvider;
9+
10+
use Magento\Framework\DataObject;
11+
use Magento\Framework\View\Element\Block\ArgumentInterface;
12+
use Magento\Framework\View\Element\BlockInterface;
13+
14+
/**
15+
* Sets the view model
16+
*/
17+
class ViewModel
18+
{
19+
/**
20+
* Key `view_model`
21+
*/
22+
private const VIEW_MODEL = 'view_model';
23+
24+
/**
25+
* @var ArgumentInterface
26+
*/
27+
private $viewModel;
28+
29+
/**
30+
* @param ArgumentInterface $viewModel
31+
*/
32+
public function __construct(ArgumentInterface $viewModel)
33+
{
34+
$this->viewModel = $viewModel;
35+
}
36+
37+
/**
38+
* Sets the view model before rendering to HTML
39+
*
40+
* @param DataObject|BlockInterface $block
41+
* @return null
42+
*/
43+
public function beforeToHtml(DataObject $block)
44+
{
45+
if (!$block->hasData(self::VIEW_MODEL)) {
46+
$block->setData(self::VIEW_MODEL, $this->viewModel);
47+
}
48+
49+
return null;
50+
}
51+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Contact\Test\Unit\Plugin\UserDataProvider;
9+
10+
use Magento\Contact\Plugin\UserDataProvider\ViewModel as ViewModelPlugin;
11+
use Magento\Framework\DataObject;
12+
use Magento\Framework\View\Element\Block\ArgumentInterface;
13+
use PHPUnit\Framework\MockObject\MockObject;
14+
use PHPUnit\Framework\TestCase;
15+
16+
/**
17+
* Unit test for the ViewModelPlugin class
18+
*/
19+
class ViewModelTest extends TestCase
20+
{
21+
/**
22+
* @var ArgumentInterface|MockObject
23+
*/
24+
private $viewModelMock;
25+
26+
/**
27+
* @var DataObject|MockObject
28+
*/
29+
private $blockMock;
30+
31+
/**
32+
* @var ViewModelPlugin
33+
*/
34+
private $plugin;
35+
36+
/**
37+
* @inheritDoc
38+
*/
39+
protected function setUp(): void
40+
{
41+
$this->viewModelMock = $this->getMockForAbstractClass(ArgumentInterface::class);
42+
$this->blockMock = $this->createMock(DataObject::class);
43+
44+
$this->plugin = new ViewModelPlugin($this->viewModelMock);
45+
}
46+
47+
/**
48+
* @dataProvider dataProvider
49+
*/
50+
public function testBeforeToHtml($hasDataResult, $setDataExpects)
51+
{
52+
$this->blockMock->expects($this->once())
53+
->method('hasData')
54+
->with('view_model')
55+
->willReturn($hasDataResult);
56+
57+
$this->blockMock->expects($setDataExpects)
58+
->method('setData')
59+
->with('view_model', $this->viewModelMock);
60+
61+
$this->plugin->beforeToHtml($this->blockMock);
62+
}
63+
64+
public function dataProvider()
65+
{
66+
return [
67+
'view model was not preset before' => [
68+
'hasData' => false,
69+
'setData' => $this->once(),
70+
],
71+
'view model was pre-installed before' => [
72+
'hasData' => true,
73+
'setData' => $this->never(),
74+
]
75+
];
76+
}
77+
}

app/code/Magento/Contact/etc/frontend/di.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,12 @@
1313
</argument>
1414
</arguments>
1515
</type>
16+
<type name="Magento\Contact\Plugin\UserDataProvider\ViewModel">
17+
<arguments>
18+
<argument name="viewModel" xsi:type="object">Magento\Contact\ViewModel\UserDataProvider</argument>
19+
</arguments>
20+
</type>
21+
<type name="Magento\Contact\Block\ContactForm">
22+
<plugin name="set_view_model" type="Magento\Contact\Plugin\UserDataProvider\ViewModel" />
23+
</type>
1624
</config>

app/code/Magento/Contact/view/frontend/layout/contact_index_index.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@
1313
<referenceContainer name="content">
1414
<block class="Magento\Contact\Block\ContactForm" name="contactForm" template="Magento_Contact::form.phtml">
1515
<container name="form.additional.info" label="Form Additional Info"/>
16-
<arguments>
17-
<argument name="view_model" xsi:type="object">Magento\Contact\ViewModel\UserDataProvider</argument>
18-
</arguments>
1916
</block>
2017
</referenceContainer>
2118
</body>

app/code/Magento/MediaGalleryUi/Controller/Adminhtml/Image/Upload.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,11 @@ public function execute()
7272
];
7373
$resultJson->setHttpResponseCode(self::HTTP_BAD_REQUEST);
7474
$resultJson->setData($responseContent);
75-
7675
return $resultJson;
7776
}
7877

7978
try {
8079
$this->uploadImage->execute($targetFolder, $type);
81-
8280
$responseCode = self::HTTP_OK;
8381
$responseContent = [
8482
'success' => true,
@@ -101,7 +99,6 @@ public function execute()
10199

102100
$resultJson->setHttpResponseCode($responseCode);
103101
$resultJson->setData($responseContent);
104-
105102
return $resultJson;
106103
}
107104
}

app/code/Magento/Paypal/etc/csp_whitelist.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@
4343
<policy id="form-action">
4444
<values>
4545
<value id="www_pilot_payflowlink_paypal" type="host">pilot-payflowlink.paypal.com</value>
46+
<value id="www_paypal" type="host">www.paypal.com</value>
47+
<value id="www_sandbox_paypal" type="host">www.sandbox.paypal.com</value>
48+
<value id="pilot_payflowlink_paypal_com" type="host">pilot-payflowlink.paypal.com</value>
4649
</values>
4750
</policy>
4851
<policy id="connect-src">

app/code/Magento/Theme/Controller/Adminhtml/System/Design/Theme/Save.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
namespace Magento\Theme\Controller\Adminhtml\System\Design\Theme;
88

99
/**
10-
* Class Save
10+
* Class Save use to save Theme data
1111
* @deprecated 100.2.0
1212
*/
1313
class Save extends \Magento\Theme\Controller\Adminhtml\System\Design\Theme
@@ -51,7 +51,9 @@ public function execute()
5151
if ($theme && !$theme->isEditable()) {
5252
throw new \Magento\Framework\Exception\LocalizedException(__('This theme is not editable.'));
5353
}
54-
$theme->addData($themeData);
54+
$theme->addData(
55+
$this->extractMutableData($themeData)
56+
);
5557
if (isset($themeData['preview']['delete'])) {
5658
$theme->getThemeImage()->removePreviewImage();
5759
}
@@ -80,4 +82,18 @@ public function execute()
8082
? $this->_redirect('adminhtml/*/edit', ['id' => $theme->getId()])
8183
: $this->_redirect('adminhtml/*/');
8284
}
85+
86+
/**
87+
* Extract required attributes
88+
*
89+
* @param array $postData
90+
* @return array
91+
*/
92+
private function extractMutableData(array $postData): array
93+
{
94+
if (!empty($postData['theme_title'])) {
95+
return ['theme_title' => $postData['theme_title']];
96+
}
97+
return [];
98+
}
8399
}

app/code/Magento/Theme/Model/Theme/Image/Path.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,6 @@ public function getImagePreviewDirectory()
103103
*/
104104
public function getTemporaryDirectory()
105105
{
106-
return $this->mediaDirectory->getRelativePath('/theme/origin');
106+
return $this->mediaDirectory->getAbsolutePath('theme/origin');
107107
}
108108
}

app/code/Magento/Theme/Test/Unit/Model/Theme/Image/PathTest.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ protected function setUp(): void
6262

6363
$this->mediaDirectory->expects($this->any())
6464
->method('getRelativePath')
65-
->with('/theme/origin')
66-
->willReturn('/theme/origin');
65+
->with('theme/origin')
66+
->willReturn('theme/origin');
6767

6868
$this->filesystem->expects($this->any())->method('getDirectoryRead')
6969
->with(DirectoryList::MEDIA)
@@ -150,8 +150,11 @@ public function testImagePreviewDirectoryGetter()
150150
*/
151151
public function testTemporaryDirectoryGetter()
152152
{
153+
$this->mediaDirectory->expects($this->any())
154+
->method('getAbsolutePath')
155+
->willReturn('/foo/theme/origin');
153156
$this->assertEquals(
154-
'/theme/origin',
157+
'/foo/theme/origin',
155158
$this->model->getTemporaryDirectory()
156159
);
157160
}

app/code/Magento/Variable/Model/Variable.php

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
*/
66
namespace Magento\Variable\Model;
77

8+
use Magento\Framework\Model\AbstractModel;
9+
use Magento\Framework\Validator\HTML\WYSIWYGValidatorInterface;
10+
use Magento\Framework\App\ObjectManager;
11+
812
/**
913
* Custom variable model
1014
*
@@ -16,7 +20,7 @@
1620
* @api
1721
* @since 100.0.2
1822
*/
19-
class Variable extends \Magento\Framework\Model\AbstractModel
23+
class Variable extends AbstractModel
2024
{
2125
const TYPE_TEXT = 'text';
2226

@@ -32,24 +36,34 @@ class Variable extends \Magento\Framework\Model\AbstractModel
3236
*/
3337
protected $_escaper = null;
3438

39+
/**
40+
* @var WYSIWYGValidatorInterface
41+
*/
42+
private $wysiwygValidator;
43+
3544
/**
3645
* @param \Magento\Framework\Model\Context $context
3746
* @param \Magento\Framework\Registry $registry
3847
* @param \Magento\Framework\Escaper $escaper
3948
* @param \Magento\Variable\Model\ResourceModel\Variable $resource
4049
* @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection
4150
* @param array $data
51+
* @param WYSIWYGValidatorInterface|null $wysiwygValidator
4252
*/
4353
public function __construct(
4454
\Magento\Framework\Model\Context $context,
4555
\Magento\Framework\Registry $registry,
4656
\Magento\Framework\Escaper $escaper,
4757
\Magento\Variable\Model\ResourceModel\Variable $resource,
4858
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
49-
array $data = []
59+
array $data = [],
60+
?WYSIWYGValidatorInterface $wysiwygValidator = null
5061
) {
5162
$this->_escaper = $escaper;
5263
parent::__construct($context, $registry, $resource, $resourceCollection, $data);
64+
65+
$this->wysiwygValidator = $wysiwygValidator
66+
?? ObjectManager::getInstance()->get(WYSIWYGValidatorInterface::class);
5367
}
5468

5569
/**
@@ -122,6 +136,21 @@ public function getValue($type = null)
122136
return $this->getData('html_value');
123137
}
124138

139+
/**
140+
* @inheritDoc
141+
*/
142+
public function beforeSave()
143+
{
144+
$html_field = $this->getValue(self::TYPE_HTML);
145+
parent::beforeSave();
146+
147+
//Validating HTML content.
148+
if ($html_field && $html_field !== $this->getOrigData('html_value')) {
149+
$this->wysiwygValidator->validate($html_field);
150+
}
151+
return $this;
152+
}
153+
125154
/**
126155
* Validation of object data. Checking for unique variable code
127156
*

0 commit comments

Comments
 (0)