@@ -64,21 +64,8 @@ public function validate(DesignConfigInterface $designConfig)
64
64
}
65
65
66
66
foreach ($ elements as $ name => $ data ) {
67
- // Load template object by configured template id
68
- $ template = $ this ->templateFactory ->create ();
69
- $ scopeId = false ;
70
- if ($ designConfig ->getScope () == 'stores ' ) {
71
- $ scopeId = $ designConfig ->getScopeId ();
72
- }
73
- $ template ->emulateDesign ($ scopeId );
74
67
$ templateId = $ data ['value ' ];
75
- if (is_numeric ($ templateId )) {
76
- $ template ->load ($ templateId );
77
- } else {
78
- $ template ->loadDefault ($ templateId );
79
- }
80
- $ text = $ template ->getTemplateText ();
81
- $ template ->revertDesign ();
68
+ $ text = $ this ->getTemplateText ($ templateId , $ designConfig );
82
69
// Check if template body has a reference to the same config path
83
70
if (preg_match_all (Template::CONSTRUCTION_TEMPLATE_PATTERN , $ text , $ constructions , PREG_SET_ORDER )) {
84
71
foreach ($ constructions as $ construction ) {
@@ -98,6 +85,37 @@ public function validate(DesignConfigInterface $designConfig)
98
85
}
99
86
}
100
87
88
+ /**
89
+ * @param $designConfig
90
+ * @return mixed
91
+ */
92
+ private function getScopeId ($ designConfig )
93
+ {
94
+ if ($ designConfig ->getScope () == 'stores ' ) {
95
+ return $ designConfig ->getScopeId ();
96
+ }
97
+ return false ;
98
+ }
99
+
100
+ /**
101
+ * @param $designConfig
102
+ * @return mixed
103
+ */
104
+ private function getTemplateText ($ templateId , $ designConfig )
105
+ {
106
+ // Load template object by configured template id
107
+ $ template = $ this ->templateFactory ->create ();
108
+ $ template ->emulateDesign ($ this ->getScopeId ($ designConfig ));
109
+ if (is_numeric ($ templateId )) {
110
+ $ template ->load ($ templateId );
111
+ } else {
112
+ $ template ->loadDefault ($ templateId );
113
+ }
114
+ $ text = $ template ->getTemplateText ();
115
+ $ template ->revertDesign ();
116
+ return $ text ;
117
+ }
118
+
101
119
/**
102
120
* Return associative array of parameters.
103
121
*
0 commit comments