9
9
10
10
use Magento \Catalog \Model \Category as ModelCategory ;
11
11
use Magento \Catalog \Model \Product as ModelProduct ;
12
+ use Magento \Eav \Model \Config ;
13
+ use Magento \Framework \App \Helper \AbstractHelper ;
14
+ use Magento \Framework \App \Helper \Context ;
15
+ use Magento \Framework \Escaper ;
16
+ use Magento \Framework \Exception \LocalizedException ;
12
17
use Magento \Framework \Filter \Template ;
18
+ use function is_object ;
19
+ use function method_exists ;
20
+ use function preg_match ;
21
+ use function strtolower ;
13
22
14
- class Output extends \Magento \Framework \App \Helper \AbstractHelper
23
+ /**
24
+ * Html output
25
+ */
26
+ class Output extends AbstractHelper
15
27
{
16
28
/**
17
29
* Array of existing handlers
@@ -37,12 +49,12 @@ class Output extends \Magento\Framework\App\Helper\AbstractHelper
37
49
/**
38
50
* Eav config
39
51
*
40
- * @var \Magento\Eav\Model\ Config
52
+ * @var Config
41
53
*/
42
54
protected $ _eavConfig ;
43
55
44
56
/**
45
- * @var \Magento\Framework\ Escaper
57
+ * @var Escaper
46
58
*/
47
59
protected $ _escaper ;
48
60
@@ -53,27 +65,32 @@ class Output extends \Magento\Framework\App\Helper\AbstractHelper
53
65
54
66
/**
55
67
* Output constructor.
56
- * @param \Magento\Framework\App\Helper\ Context $context
57
- * @param \Magento\Eav\Model\ Config $eavConfig
68
+ * @param Context $context
69
+ * @param Config $eavConfig
58
70
* @param Data $catalogData
59
- * @param \Magento\Framework\ Escaper $escaper
71
+ * @param Escaper $escaper
60
72
* @param array $directivePatterns
73
+ * @param array $handlers
61
74
*/
62
75
public function __construct (
63
- \ Magento \ Framework \ App \ Helper \ Context $ context ,
64
- \ Magento \ Eav \ Model \ Config $ eavConfig ,
76
+ Context $ context ,
77
+ Config $ eavConfig ,
65
78
Data $ catalogData ,
66
- \Magento \Framework \Escaper $ escaper ,
67
- $ directivePatterns = []
79
+ Escaper $ escaper ,
80
+ $ directivePatterns = [],
81
+ array $ handlers = []
68
82
) {
69
83
$ this ->_eavConfig = $ eavConfig ;
70
84
$ this ->_catalogData = $ catalogData ;
71
85
$ this ->_escaper = $ escaper ;
72
86
$ this ->directivePatterns = $ directivePatterns ;
87
+ $ this ->_handlers = $ handlers ;
73
88
parent ::__construct ($ context );
74
89
}
75
90
76
91
/**
92
+ * Return template processor
93
+ *
77
94
* @return Template
78
95
*/
79
96
protected function _getTemplateProcessor ()
@@ -115,8 +132,7 @@ public function addHandler($method, $handler)
115
132
*/
116
133
public function getHandlers ($ method )
117
134
{
118
- $ method = strtolower ($ method );
119
- return $ this ->_handlers [$ method ] ?? [];
135
+ return $ this ->_handlers [strtolower ($ method )] ?? [];
120
136
}
121
137
122
138
/**
@@ -145,21 +161,21 @@ public function process($method, $result, $params)
145
161
* @param string $attributeName
146
162
* @return string
147
163
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
148
- * @throws \Magento\Framework\Exception\ LocalizedException
164
+ * @throws LocalizedException
149
165
*/
150
166
public function productAttribute ($ product , $ attributeHtml , $ attributeName )
151
167
{
152
168
$ attribute = $ this ->_eavConfig ->getAttribute (ModelProduct::ENTITY , $ attributeName );
153
169
if ($ attribute &&
154
170
$ attribute ->getId () &&
155
- $ attribute ->getFrontendInput () != 'media_image ' &&
171
+ $ attribute ->getFrontendInput () !== 'media_image ' &&
156
172
(!$ attribute ->getIsHtmlAllowedOnFront () &&
157
173
!$ attribute ->getIsWysiwygEnabled ())
158
174
) {
159
- if ($ attribute ->getFrontendInput () != 'price ' ) {
175
+ if ($ attribute ->getFrontendInput () !== 'price ' ) {
160
176
$ attributeHtml = $ this ->_escaper ->escapeHtml ($ attributeHtml );
161
177
}
162
- if ($ attribute ->getFrontendInput () == 'textarea ' ) {
178
+ if ($ attribute ->getFrontendInput () === 'textarea ' ) {
163
179
$ attributeHtml = nl2br ($ attributeHtml );
164
180
}
165
181
}
@@ -187,14 +203,14 @@ public function productAttribute($product, $attributeHtml, $attributeName)
187
203
* @param string $attributeHtml
188
204
* @param string $attributeName
189
205
* @return string
190
- * @throws \Magento\Framework\Exception\ LocalizedException
206
+ * @throws LocalizedException
191
207
*/
192
208
public function categoryAttribute ($ category , $ attributeHtml , $ attributeName )
193
209
{
194
210
$ attribute = $ this ->_eavConfig ->getAttribute (ModelCategory::ENTITY , $ attributeName );
195
211
196
212
if ($ attribute &&
197
- $ attribute ->getFrontendInput () != 'image ' &&
213
+ $ attribute ->getFrontendInput () !== 'image ' &&
198
214
(!$ attribute ->getIsHtmlAllowedOnFront () &&
199
215
!$ attribute ->getIsWysiwygEnabled ())
200
216
) {
0 commit comments