@@ -45,20 +45,29 @@ class Output extends \Magento\Framework\App\Helper\AbstractHelper
45
45
protected $ _escaper ;
46
46
47
47
/**
48
+ * @var array
49
+ */
50
+ private $ directivePatterns ;
51
+
52
+ /**
53
+ * Output constructor.
48
54
* @param \Magento\Framework\App\Helper\Context $context
49
55
* @param \Magento\Eav\Model\Config $eavConfig
50
56
* @param Data $catalogData
51
57
* @param \Magento\Framework\Escaper $escaper
58
+ * @param array $directivePatterns
52
59
*/
53
60
public function __construct (
54
61
\Magento \Framework \App \Helper \Context $ context ,
55
62
\Magento \Eav \Model \Config $ eavConfig ,
56
63
Data $ catalogData ,
57
- \Magento \Framework \Escaper $ escaper
64
+ \Magento \Framework \Escaper $ escaper ,
65
+ $ directivePatterns = []
58
66
) {
59
67
$ this ->_eavConfig = $ eavConfig ;
60
68
$ this ->_catalogData = $ catalogData ;
61
69
$ this ->_escaper = $ escaper ;
70
+ $ this ->directivePatterns = $ directivePatterns ;
62
71
parent ::__construct ($ context );
63
72
}
64
73
@@ -134,6 +143,7 @@ public function process($method, $result, $params)
134
143
* @param string $attributeName
135
144
* @return string
136
145
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
146
+ * @throws \Magento\Framework\Exception\LocalizedException
137
147
*/
138
148
public function productAttribute ($ product , $ attributeHtml , $ attributeName )
139
149
{
@@ -151,10 +161,12 @@ public function productAttribute($product, $attributeHtml, $attributeName)
151
161
$ attributeHtml = nl2br ($ attributeHtml );
152
162
}
153
163
}
154
- if ($ attribute ->getIsHtmlAllowedOnFront () && $ attribute ->getIsWysiwygEnabled ()) {
155
- if ($ this ->_catalogData ->isUrlDirectivesParsingAllowed ()) {
156
- $ attributeHtml = $ this ->_getTemplateProcessor ()->filter ($ attributeHtml );
157
- }
164
+ if ($ attributeHtml !== null
165
+ && $ attribute ->getIsHtmlAllowedOnFront ()
166
+ && $ attribute ->getIsWysiwygEnabled ()
167
+ && $ this ->isDirectivesExists ($ attributeHtml )
168
+ ) {
169
+ $ attributeHtml = $ this ->_getTemplateProcessor ()->filter ($ attributeHtml );
158
170
}
159
171
160
172
$ attributeHtml = $ this ->process (
@@ -173,6 +185,7 @@ public function productAttribute($product, $attributeHtml, $attributeName)
173
185
* @param string $attributeHtml
174
186
* @param string $attributeName
175
187
* @return string
188
+ * @throws \Magento\Framework\Exception\LocalizedException
176
189
*/
177
190
public function categoryAttribute ($ category , $ attributeHtml , $ attributeName )
178
191
{
@@ -185,10 +198,13 @@ public function categoryAttribute($category, $attributeHtml, $attributeName)
185
198
) {
186
199
$ attributeHtml = $ this ->_escaper ->escapeHtml ($ attributeHtml );
187
200
}
188
- if ($ attribute ->getIsHtmlAllowedOnFront () && $ attribute ->getIsWysiwygEnabled ()) {
189
- if ($ this ->_catalogData ->isUrlDirectivesParsingAllowed ()) {
190
- $ attributeHtml = $ this ->_getTemplateProcessor ()->filter ($ attributeHtml );
191
- }
201
+ if ($ attributeHtml !== null
202
+ && $ attribute ->getIsHtmlAllowedOnFront ()
203
+ && $ attribute ->getIsWysiwygEnabled ()
204
+ && $ this ->isDirectivesExists ($ attributeHtml )
205
+
206
+ ) {
207
+ $ attributeHtml = $ this ->_getTemplateProcessor ()->filter ($ attributeHtml );
192
208
}
193
209
$ attributeHtml = $ this ->process (
194
210
'categoryAttribute ' ,
@@ -197,4 +213,23 @@ public function categoryAttribute($category, $attributeHtml, $attributeName)
197
213
);
198
214
return $ attributeHtml ;
199
215
}
216
+
217
+ /**
218
+ * Check if string has directives
219
+ *
220
+ * @param string $attributeHtml
221
+ * @return bool
222
+ */
223
+ public function isDirectivesExists ($ attributeHtml )
224
+ {
225
+ $ matches = false ;
226
+ foreach ($ this ->directivePatterns as $ pattern )
227
+ {
228
+ if (preg_match ($ pattern , $ attributeHtml ))
229
+ {
230
+ $ matches = true ;
231
+ }
232
+ }
233
+ return $ matches ;
234
+ }
200
235
}
0 commit comments