5
5
*/
6
6
declare (strict_types=1 );
7
7
8
- namespace Magento \Theme \Plugin ;
8
+ namespace Magento \Theme \Model \ Config ;
9
9
10
- use Magento \Config \Model \Config \PathValidator ;
11
10
use Magento \Config \Model \Config \Structure ;
12
- use Magento \Config \Model \Config \Structure \Element \Field ;
13
11
use Magento \Framework \Exception \ValidatorException ;
14
12
use Magento \Theme \Model \DesignConfigRepository ;
15
13
16
- class DesignPathValidatorPlugin
14
+ class PathValidator extends \ Magento \ Config \ Model \ Config \PathValidator
17
15
{
18
16
/**
19
17
* @param Structure $structure
@@ -23,35 +21,19 @@ public function __construct(
23
21
private readonly Structure $ structure ,
24
22
private readonly DesignConfigRepository $ designConfigRepository
25
23
) {
24
+ parent ::__construct ($ structure );
26
25
}
27
26
28
27
/**
29
- * Allow setting design configuration from cli
30
- *
31
- * @param PathValidator $subject
32
- * @param callable $proceed
33
- * @param string $path
34
- * @return true
35
- * @throws ValidatorException
36
- * @SuppressWarnings(PHPMD.UnusedFormalParameter)
28
+ * @inheritdoc
37
29
*/
38
- public function aroundValidate ( PathValidator $ subject , callable $ proceed , $ path ): bool
30
+ public function validate ( $ path )
39
31
{
40
32
if (stripos ($ path , 'design/ ' ) !== 0 ) {
41
- return $ proceed ($ path );
42
- }
43
-
44
- $ element = $ this ->structure ->getElementByConfigPath ($ path );
45
- if ($ element instanceof Field && $ element ->getConfigPath ()) {
46
- $ path = $ element ->getConfigPath ();
33
+ return parent ::validate ($ path );
47
34
}
48
35
49
- $ allPaths = array_merge ($ this ->structure ->getFieldPaths (), $ this ->getDesignFieldPaths ());
50
-
51
- if (!array_key_exists ($ path , $ allPaths )) {
52
- throw new ValidatorException (__ ('The "%1" path doesn \'t exist. Verify and try again. ' , $ path ));
53
- }
54
- return true ;
36
+ return $ this ->validateDesignPath ($ path );
55
37
}
56
38
57
39
/**
@@ -69,4 +51,26 @@ private function getDesignFieldPaths(): array
69
51
}
70
52
return $ data ;
71
53
}
54
+
55
+ /**
56
+ * Validate design path configurations
57
+ *
58
+ * @param string $path
59
+ * @return bool
60
+ * @throws ValidatorException
61
+ */
62
+ private function validateDesignPath (string $ path ): bool
63
+ {
64
+ $ element = $ this ->structure ->getElementByConfigPath ($ path );
65
+ if ($ element instanceof Structure \Element \Field && $ element ->getConfigPath ()) {
66
+ $ path = $ element ->getConfigPath ();
67
+ }
68
+
69
+ $ allPaths = array_merge ($ this ->structure ->getFieldPaths (), $ this ->getDesignFieldPaths ());
70
+
71
+ if (!array_key_exists ($ path , $ allPaths )) {
72
+ throw new ValidatorException (__ ('The "%1" path doesn \'t exist. Verify and try again. ' , $ path ));
73
+ }
74
+ return true ;
75
+ }
72
76
}
0 commit comments