Skip to content

Commit c282c69

Browse files
ENGCOM-5757: #12371 allows to add handlers via di #24405
2 parents f5a135c + 114b7fc commit c282c69

File tree

1 file changed

+34
-18
lines changed

1 file changed

+34
-18
lines changed

app/code/Magento/Catalog/Helper/Output.php

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,21 @@
99

1010
use Magento\Catalog\Model\Category as ModelCategory;
1111
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;
1217
use Magento\Framework\Filter\Template;
18+
use function is_object;
19+
use function method_exists;
20+
use function preg_match;
21+
use function strtolower;
1322

14-
class Output extends \Magento\Framework\App\Helper\AbstractHelper
23+
/**
24+
* Html output
25+
*/
26+
class Output extends AbstractHelper
1527
{
1628
/**
1729
* Array of existing handlers
@@ -37,12 +49,12 @@ class Output extends \Magento\Framework\App\Helper\AbstractHelper
3749
/**
3850
* Eav config
3951
*
40-
* @var \Magento\Eav\Model\Config
52+
* @var Config
4153
*/
4254
protected $_eavConfig;
4355

4456
/**
45-
* @var \Magento\Framework\Escaper
57+
* @var Escaper
4658
*/
4759
protected $_escaper;
4860

@@ -53,27 +65,32 @@ class Output extends \Magento\Framework\App\Helper\AbstractHelper
5365

5466
/**
5567
* 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
5870
* @param Data $catalogData
59-
* @param \Magento\Framework\Escaper $escaper
71+
* @param Escaper $escaper
6072
* @param array $directivePatterns
73+
* @param array $handlers
6174
*/
6275
public function __construct(
63-
\Magento\Framework\App\Helper\Context $context,
64-
\Magento\Eav\Model\Config $eavConfig,
76+
Context $context,
77+
Config $eavConfig,
6578
Data $catalogData,
66-
\Magento\Framework\Escaper $escaper,
67-
$directivePatterns = []
79+
Escaper $escaper,
80+
$directivePatterns = [],
81+
array $handlers = []
6882
) {
6983
$this->_eavConfig = $eavConfig;
7084
$this->_catalogData = $catalogData;
7185
$this->_escaper = $escaper;
7286
$this->directivePatterns = $directivePatterns;
87+
$this->_handlers = $handlers;
7388
parent::__construct($context);
7489
}
7590

7691
/**
92+
* Return template processor
93+
*
7794
* @return Template
7895
*/
7996
protected function _getTemplateProcessor()
@@ -115,8 +132,7 @@ public function addHandler($method, $handler)
115132
*/
116133
public function getHandlers($method)
117134
{
118-
$method = strtolower($method);
119-
return $this->_handlers[$method] ?? [];
135+
return $this->_handlers[strtolower($method)] ?? [];
120136
}
121137

122138
/**
@@ -145,21 +161,21 @@ public function process($method, $result, $params)
145161
* @param string $attributeName
146162
* @return string
147163
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
148-
* @throws \Magento\Framework\Exception\LocalizedException
164+
* @throws LocalizedException
149165
*/
150166
public function productAttribute($product, $attributeHtml, $attributeName)
151167
{
152168
$attribute = $this->_eavConfig->getAttribute(ModelProduct::ENTITY, $attributeName);
153169
if ($attribute &&
154170
$attribute->getId() &&
155-
$attribute->getFrontendInput() != 'media_image' &&
171+
$attribute->getFrontendInput() !== 'media_image' &&
156172
(!$attribute->getIsHtmlAllowedOnFront() &&
157173
!$attribute->getIsWysiwygEnabled())
158174
) {
159-
if ($attribute->getFrontendInput() != 'price') {
175+
if ($attribute->getFrontendInput() !== 'price') {
160176
$attributeHtml = $this->_escaper->escapeHtml($attributeHtml);
161177
}
162-
if ($attribute->getFrontendInput() == 'textarea') {
178+
if ($attribute->getFrontendInput() === 'textarea') {
163179
$attributeHtml = nl2br($attributeHtml);
164180
}
165181
}
@@ -187,14 +203,14 @@ public function productAttribute($product, $attributeHtml, $attributeName)
187203
* @param string $attributeHtml
188204
* @param string $attributeName
189205
* @return string
190-
* @throws \Magento\Framework\Exception\LocalizedException
206+
* @throws LocalizedException
191207
*/
192208
public function categoryAttribute($category, $attributeHtml, $attributeName)
193209
{
194210
$attribute = $this->_eavConfig->getAttribute(ModelCategory::ENTITY, $attributeName);
195211

196212
if ($attribute &&
197-
$attribute->getFrontendInput() != 'image' &&
213+
$attribute->getFrontendInput() !== 'image' &&
198214
(!$attribute->getIsHtmlAllowedOnFront() &&
199215
!$attribute->getIsWysiwygEnabled())
200216
) {

0 commit comments

Comments
 (0)