Skip to content

Commit 029acac

Browse files
committed
#12371 allows to add handlers via di
1 parent 9fc254f commit 029acac

File tree

1 file changed

+29
-18
lines changed

1 file changed

+29
-18
lines changed

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

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,18 @@
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+
class Output extends AbstractHelper
1524
{
1625
/**
1726
* Array of existing handlers
@@ -37,12 +46,12 @@ class Output extends \Magento\Framework\App\Helper\AbstractHelper
3746
/**
3847
* Eav config
3948
*
40-
* @var \Magento\Eav\Model\Config
49+
* @var Config
4150
*/
4251
protected $_eavConfig;
4352

4453
/**
45-
* @var \Magento\Framework\Escaper
54+
* @var Escaper
4655
*/
4756
protected $_escaper;
4857

@@ -53,23 +62,26 @@ class Output extends \Magento\Framework\App\Helper\AbstractHelper
5362

5463
/**
5564
* Output constructor.
56-
* @param \Magento\Framework\App\Helper\Context $context
57-
* @param \Magento\Eav\Model\Config $eavConfig
65+
* @param Context $context
66+
* @param Config $eavConfig
5867
* @param Data $catalogData
59-
* @param \Magento\Framework\Escaper $escaper
68+
* @param Escaper $escaper
6069
* @param array $directivePatterns
70+
* @param array $handlers
6171
*/
6272
public function __construct(
63-
\Magento\Framework\App\Helper\Context $context,
64-
\Magento\Eav\Model\Config $eavConfig,
73+
Context $context,
74+
Config $eavConfig,
6575
Data $catalogData,
66-
\Magento\Framework\Escaper $escaper,
67-
$directivePatterns = []
76+
Escaper $escaper,
77+
$directivePatterns = [],
78+
array $handlers = []
6879
) {
6980
$this->_eavConfig = $eavConfig;
7081
$this->_catalogData = $catalogData;
7182
$this->_escaper = $escaper;
7283
$this->directivePatterns = $directivePatterns;
84+
$this->_handlers = $handlers;
7385
parent::__construct($context);
7486
}
7587

@@ -115,8 +127,7 @@ public function addHandler($method, $handler)
115127
*/
116128
public function getHandlers($method)
117129
{
118-
$method = strtolower($method);
119-
return $this->_handlers[$method] ?? [];
130+
return $this->_handlers[strtolower($method)] ?? [];
120131
}
121132

122133
/**
@@ -145,21 +156,21 @@ public function process($method, $result, $params)
145156
* @param string $attributeName
146157
* @return string
147158
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
148-
* @throws \Magento\Framework\Exception\LocalizedException
159+
* @throws LocalizedException
149160
*/
150161
public function productAttribute($product, $attributeHtml, $attributeName)
151162
{
152163
$attribute = $this->_eavConfig->getAttribute(ModelProduct::ENTITY, $attributeName);
153164
if ($attribute &&
154165
$attribute->getId() &&
155-
$attribute->getFrontendInput() != 'media_image' &&
166+
$attribute->getFrontendInput() !== 'media_image' &&
156167
(!$attribute->getIsHtmlAllowedOnFront() &&
157168
!$attribute->getIsWysiwygEnabled())
158169
) {
159-
if ($attribute->getFrontendInput() != 'price') {
170+
if ($attribute->getFrontendInput() !== 'price') {
160171
$attributeHtml = $this->_escaper->escapeHtml($attributeHtml);
161172
}
162-
if ($attribute->getFrontendInput() == 'textarea') {
173+
if ($attribute->getFrontendInput() === 'textarea') {
163174
$attributeHtml = nl2br($attributeHtml);
164175
}
165176
}
@@ -187,14 +198,14 @@ public function productAttribute($product, $attributeHtml, $attributeName)
187198
* @param string $attributeHtml
188199
* @param string $attributeName
189200
* @return string
190-
* @throws \Magento\Framework\Exception\LocalizedException
201+
* @throws LocalizedException
191202
*/
192203
public function categoryAttribute($category, $attributeHtml, $attributeName)
193204
{
194205
$attribute = $this->_eavConfig->getAttribute(ModelCategory::ENTITY, $attributeName);
195206

196207
if ($attribute &&
197-
$attribute->getFrontendInput() != 'image' &&
208+
$attribute->getFrontendInput() !== 'image' &&
198209
(!$attribute->getIsHtmlAllowedOnFront() &&
199210
!$attribute->getIsWysiwygEnabled())
200211
) {

0 commit comments

Comments
 (0)