Skip to content

Commit d8e9787

Browse files
ENGCOM-8701: Allow configuration paths based on system.xml #31621
2 parents d925e09 + 41d96c0 commit d8e9787

File tree

4 files changed

+21
-1
lines changed

4 files changed

+21
-1
lines changed

app/code/Magento/Config/Model/Config/PathValidator.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
namespace Magento\Config\Model\Config;
88

9+
use Magento\Config\Model\Config\Structure\Element\Field;
910
use Magento\Framework\Exception\ValidatorException;
1011

1112
/**
@@ -40,6 +41,11 @@ public function __construct(Structure $structure)
4041
*/
4142
public function validate($path)
4243
{
44+
$element = $this->structure->getElementByConfigPath($path);
45+
if ($element instanceof Field && $element->getConfigPath()) {
46+
$path = $element->getConfigPath();
47+
}
48+
4349
$allPaths = $this->structure->getFieldPaths();
4450

4551
if (!array_key_exists($path, $allPaths)) {

app/code/Magento/Config/Model/Config/Structure.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ public function getElementByConfigPath($path)
191191
{
192192
$allPaths = $this->getFieldPaths();
193193

194-
if (isset($allPaths[$path])) {
194+
if (isset($allPaths[$path]) && is_array($allPaths[$path])) {
195195
$path = array_shift($allPaths[$path]);
196196
}
197197

dev/tests/integration/testsuite/Magento/Config/Console/Command/ConfigSetCommandTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
namespace Magento\Config\Console\Command;
88

99
use Magento\Config\Model\Config\Backend\Admin\Custom;
10+
use Magento\Config\Model\Config\PathValidator;
1011
use Magento\Config\Model\Config\Structure\Converter;
1112
use Magento\Config\Model\Config\Structure\Data as StructureData;
1213
use Magento\Directory\Model\Currency;
@@ -444,6 +445,15 @@ public function configSetValidDataProvider()
444445
];
445446
}
446447

448+
/**
449+
* Test validate path when field has custom config_path
450+
*/
451+
public function testValidatePathWithCustomConfigPath(): void
452+
{
453+
$pathValidator = $this->objectManager->get(PathValidator::class);
454+
$this->assertTrue($pathValidator->validate('general/group/subgroup/second_field'));
455+
}
456+
447457
/**
448458
* Set configuration and check this value from DB with success message this command should display
449459
*

dev/tests/integration/testsuite/Magento/Config/_files/system.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
<field id="field" translate="label" type="text" sortOrder="100" showInDefault="1" showInWebsite="1" showInStore="0">
1414
<label>Label</label>
1515
</field>
16+
<field id="second_field" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="0">
17+
<label>Label Second</label>
18+
<config_path>custom/config_path/second_field</config_path>
19+
</field>
1620
</group>
1721
</group>
1822
</section>

0 commit comments

Comments
 (0)