File tree 4 files changed +21
-1
lines changed
app/code/Magento/Config/Model/Config
dev/tests/integration/testsuite/Magento/Config
4 files changed +21
-1
lines changed Original file line number Diff line number Diff line change 6
6
7
7
namespace Magento \Config \Model \Config ;
8
8
9
+ use Magento \Config \Model \Config \Structure \Element \Field ;
9
10
use Magento \Framework \Exception \ValidatorException ;
10
11
11
12
/**
@@ -40,6 +41,11 @@ public function __construct(Structure $structure)
40
41
*/
41
42
public function validate ($ path )
42
43
{
44
+ $ element = $ this ->structure ->getElementByConfigPath ($ path );
45
+ if ($ element instanceof Field && $ element ->getConfigPath ()) {
46
+ $ path = $ element ->getConfigPath ();
47
+ }
48
+
43
49
$ allPaths = $ this ->structure ->getFieldPaths ();
44
50
45
51
if (!array_key_exists ($ path , $ allPaths )) {
Original file line number Diff line number Diff line change @@ -191,7 +191,7 @@ public function getElementByConfigPath($path)
191
191
{
192
192
$ allPaths = $ this ->getFieldPaths ();
193
193
194
- if (isset ($ allPaths [$ path ])) {
194
+ if (isset ($ allPaths [$ path ]) && is_array ( $ allPaths [ $ path ]) ) {
195
195
$ path = array_shift ($ allPaths [$ path ]);
196
196
}
197
197
Original file line number Diff line number Diff line change 7
7
namespace Magento \Config \Console \Command ;
8
8
9
9
use Magento \Config \Model \Config \Backend \Admin \Custom ;
10
+ use Magento \Config \Model \Config \PathValidator ;
10
11
use Magento \Config \Model \Config \Structure \Converter ;
11
12
use Magento \Config \Model \Config \Structure \Data as StructureData ;
12
13
use Magento \Directory \Model \Currency ;
@@ -444,6 +445,15 @@ public function configSetValidDataProvider()
444
445
];
445
446
}
446
447
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
+
447
457
/**
448
458
* Set configuration and check this value from DB with success message this command should display
449
459
*
Original file line number Diff line number Diff line change 13
13
<field id =" field" translate =" label" type =" text" sortOrder =" 100" showInDefault =" 1" showInWebsite =" 1" showInStore =" 0" >
14
14
<label >Label</label >
15
15
</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 >
16
20
</group >
17
21
</group >
18
22
</section >
You can’t perform that action at this time.
0 commit comments