Skip to content

Commit a836033

Browse files
committed
ACP2E-3324: added admin save data validator to cli set data
1 parent 282b878 commit a836033

File tree

4 files changed

+74
-7
lines changed

4 files changed

+74
-7
lines changed

app/code/Magento/Theme/Model/Design/Config/Validator.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ public function validate(DesignConfigInterface $designConfig)
6666

6767
foreach ($elements as $name => $data) {
6868
$templateId = $data['value'];
69+
if (!$templateId) {
70+
continue;
71+
}
6972
$text = $this->getTemplateText($templateId, $designConfig);
7073
// Check if template body has a reference to the same config path
7174
if (preg_match_all(Template::CONSTRUCTION_TEMPLATE_PATTERN, $text, $constructions, PREG_SET_ORDER)) {
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
/**
3+
* Copyright 2024 Adobe
4+
* All Rights Reserved.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Theme\Plugin;
9+
10+
use Magento\Config\Console\Command\ConfigSet\ProcessorFacade;
11+
use Magento\Framework\Config\File\ConfigFilePool;
12+
use Magento\Framework\Exception\LocalizedException;
13+
use Magento\Theme\Model\Data\Design\ConfigFactory;
14+
use Magento\Theme\Model\Design\Config\Validator;
15+
16+
class DesignProcessorFacade
17+
{
18+
/**
19+
* @param Validator $validator
20+
* @param ConfigFactory $configFactory
21+
*/
22+
public function __construct(
23+
private Validator $validator,
24+
private ConfigFactory $configFactory
25+
) {
26+
}
27+
28+
/**
29+
* Plugin to validate design configuration data before saving
30+
*
31+
* @param ProcessorFacade $subject
32+
* @param string $path
33+
* @param string $value
34+
* @param string $scope
35+
* @param string $scopeCode
36+
* @param bool $lock
37+
* @param string $lockTarget
38+
* @return string
39+
* @throws LocalizedException
40+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
41+
*/
42+
public function beforeProcessWithLockTarget(
43+
ProcessorFacade $subject,
44+
$path,
45+
$value,
46+
$scope,
47+
$scopeCode,
48+
$lock,
49+
$lockTarget = ConfigFilePool::APP_ENV
50+
) {
51+
if (stripos($path, 'design/') === 0) {
52+
$savePath = str_replace('design/', '', $path);
53+
$savePath = str_replace('/', '_', $savePath);
54+
$designConfig = $this->configFactory->create($scope, $scopeCode, [$savePath => $value]);
55+
$this->validator->validate($designConfig);
56+
}
57+
58+
return [$path, $value, $scope, $scopeCode, $lock, $lockTarget];
59+
}
60+
}

app/code/Magento/Theme/etc/adminhtml/di.xml

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,8 @@
3333
</argument>
3434
</arguments>
3535
</type>
36-
<type name="Magento\Theme\Model\Design\Config\Validator">
37-
<arguments>
38-
<argument name="fields" xsi:type="array">
39-
<item name="header" xsi:type="string">email_header_template</item>
40-
<item name="footer" xsi:type="string">email_footer_template</item>
41-
</argument>
42-
</arguments>
36+
<type name="Magento\Config\Console\Command\ConfigSet\ProcessorFacade">
37+
<plugin name="validate_design_config"
38+
type="Magento\Theme\Plugin\DesignProcessorFacade"/>
4339
</type>
4440
</config>

app/code/Magento/Theme/etc/di.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,14 @@
334334
<type name="Magento\Config\Console\Command\LocaleEmulator">
335335
<plugin name="themeForLocaleEmulator" type="Magento\Theme\Plugin\LocaleEmulator"/>
336336
</type>
337+
<type name="Magento\Theme\Model\Design\Config\Validator">
338+
<arguments>
339+
<argument name="fields" xsi:type="array">
340+
<item name="header" xsi:type="string">email_header_template</item>
341+
<item name="footer" xsi:type="string">email_footer_template</item>
342+
</argument>
343+
</arguments>
344+
</type>
337345
<type name="Magento\Config\Console\Command\ConfigSet\ProcessorFacade">
338346
<arguments>
339347
<argument name="pathValidator" xsi:type="object">Magento\Theme\Model\Config\PathValidator</argument>

0 commit comments

Comments
 (0)