Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Member Functions | Protected Attributes
Output Class Reference
Inheritance diagram for Output:
AbstractHelper

Public Member Functions

 __construct (\Magento\Framework\App\Helper\Context $context, \Magento\Eav\Model\Config $eavConfig, Data $catalogData, \Magento\Framework\Escaper $escaper, $directivePatterns=[])
 
 addHandler ($method, $handler)
 
 getHandlers ($method)
 
 process ($method, $result, $params)
 
 productAttribute ($product, $attributeHtml, $attributeName)
 
 categoryAttribute ($category, $attributeHtml, $attributeName)
 
 isDirectivesExists ($attributeHtml)
 
- Public Member Functions inherited from AbstractHelper
 __construct (Context $context)
 
 isModuleOutputEnabled ($moduleName=null)
 

Protected Member Functions

 _getTemplateProcessor ()
 
- Protected Member Functions inherited from AbstractHelper
 _getRequest ()
 
 _getModuleName ()
 
 _getUrl ($route, $params=[])
 

Protected Attributes

 $_handlers
 
 $_templateProcessor = null
 
 $_catalogData = null
 
 $_eavConfig
 
 $_escaper
 
- Protected Attributes inherited from AbstractHelper
 $_moduleName
 
 $_request
 
 $_moduleManager
 
 $_logger
 
 $_urlBuilder
 
 $_httpHeader
 
 $_eventManager
 
 $_remoteAddress
 
 $urlEncoder
 
 $urlDecoder
 
 $scopeConfig
 
 $_cacheConfig
 

Detailed Description

Definition at line 14 of file Output.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( \Magento\Framework\App\Helper\Context  $context,
\Magento\Eav\Model\Config  $eavConfig,
Data  $catalogData,
\Magento\Framework\Escaper  $escaper,
  $directivePatterns = [] 
)

Output constructor.

Parameters
\Magento\Framework\App\Helper\Context$context
\Magento\Eav\Model\Config$eavConfig
Data$catalogData
\Magento\Framework\Escaper$escaper
array$directivePatterns

Definition at line 62 of file Output.php.

68  {
69  $this->_eavConfig = $eavConfig;
70  $this->_catalogData = $catalogData;
71  $this->_escaper = $escaper;
72  $this->directivePatterns = $directivePatterns;
73  parent::__construct($context);
74  }

Member Function Documentation

◆ _getTemplateProcessor()

_getTemplateProcessor ( )
protected
Returns
Template

Definition at line 79 of file Output.php.

80  {
81  if (null === $this->_templateProcessor) {
82  $this->_templateProcessor = $this->_catalogData->getPageTemplateProcessor();
83  }
84 
86  }

◆ addHandler()

addHandler (   $method,
  $handler 
)

Adding method handler

Parameters
string$method
object$handler
Returns
$this

Definition at line 95 of file Output.php.

96  {
97  if (!is_object($handler)) {
98  return $this;
99  }
100  $method = strtolower($method);
101 
102  if (!isset($this->_handlers[$method])) {
103  $this->_handlers[$method] = [];
104  }
105 
106  $this->_handlers[$method][] = $handler;
107  return $this;
108  }
$method
Definition: info.phtml:13
catch(\Exception $e) $handler
Definition: index.php:30

◆ categoryAttribute()

categoryAttribute (   $category,
  $attributeHtml,
  $attributeName 
)

Prepare category attribute html output

Parameters
ModelCategory$category
string$attributeHtml
string$attributeName
Returns
string
Exceptions

Definition at line 192 of file Output.php.

193  {
194  $attribute = $this->_eavConfig->getAttribute(ModelCategory::ENTITY, $attributeName);
195 
196  if ($attribute &&
197  $attribute->getFrontendInput() != 'image' &&
198  (!$attribute->getIsHtmlAllowedOnFront() &&
199  !$attribute->getIsWysiwygEnabled())
200  ) {
201  $attributeHtml = $this->_escaper->escapeHtml($attributeHtml);
202  }
203  if ($attributeHtml !== null
204  && $attribute->getIsHtmlAllowedOnFront()
205  && $attribute->getIsWysiwygEnabled()
206  && $this->isDirectivesExists($attributeHtml)
207 
208  ) {
209  $attributeHtml = $this->_getTemplateProcessor()->filter($attributeHtml);
210  }
211  $attributeHtml = $this->process(
212  'categoryAttribute',
213  $attributeHtml,
214  ['category' => $category, 'attribute' => $attributeName]
215  );
216  return $attributeHtml;
217  }
process($method, $result, $params)
Definition: Output.php:130
isDirectivesExists($attributeHtml)
Definition: Output.php:225

◆ getHandlers()

getHandlers (   $method)

Get all handlers for some method

Parameters
string$method
Returns
array

Definition at line 116 of file Output.php.

117  {
118  $method = strtolower($method);
119  return $this->_handlers[$method] ?? [];
120  }
$method
Definition: info.phtml:13

◆ isDirectivesExists()

isDirectivesExists (   $attributeHtml)

Check if string has directives

Parameters
string$attributeHtml
Returns
bool

Definition at line 225 of file Output.php.

226  {
227  $matches = false;
228  foreach ($this->directivePatterns as $pattern) {
229  if (preg_match($pattern, $attributeHtml)) {
230  $matches = true;
231  break;
232  }
233  }
234  return $matches;
235  }
$pattern
Definition: website.php:22

◆ process()

process (   $method,
  $result,
  $params 
)

Process all method handlers

Parameters
string$method
mixed$result
array$params
Returns
mixed

Definition at line 130 of file Output.php.

131  {
132  foreach ($this->getHandlers($method) as $handler) {
133  if (method_exists($handler, $method)) {
134  $result = $handler->{$method}($this, $result, $params);
135  }
136  }
137  return $result;
138  }
$method
Definition: info.phtml:13
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
Definition: website.php:18
catch(\Exception $e) $handler
Definition: index.php:30

◆ productAttribute()

productAttribute (   $product,
  $attributeHtml,
  $attributeName 
)

Prepare product attribute html output

Parameters
ModelProduct$product
string$attributeHtml
string$attributeName
Returns
string @SuppressWarnings(PHPMD.CyclomaticComplexity)
Exceptions

Definition at line 150 of file Output.php.

151  {
152  $attribute = $this->_eavConfig->getAttribute(ModelProduct::ENTITY, $attributeName);
153  if ($attribute &&
154  $attribute->getId() &&
155  $attribute->getFrontendInput() != 'media_image' &&
156  (!$attribute->getIsHtmlAllowedOnFront() &&
157  !$attribute->getIsWysiwygEnabled())
158  ) {
159  if ($attribute->getFrontendInput() != 'price') {
160  $attributeHtml = $this->_escaper->escapeHtml($attributeHtml);
161  }
162  if ($attribute->getFrontendInput() == 'textarea') {
163  $attributeHtml = nl2br($attributeHtml);
164  }
165  }
166  if ($attributeHtml !== null
167  && $attribute->getIsHtmlAllowedOnFront()
168  && $attribute->getIsWysiwygEnabled()
169  && $this->isDirectivesExists($attributeHtml)
170  ) {
171  $attributeHtml = $this->_getTemplateProcessor()->filter($attributeHtml);
172  }
173 
174  $attributeHtml = $this->process(
175  'productAttribute',
176  $attributeHtml,
177  ['product' => $product, 'attribute' => $attributeName]
178  );
179 
180  return $attributeHtml;
181  }
process($method, $result, $params)
Definition: Output.php:130
isDirectivesExists($attributeHtml)
Definition: Output.php:225

Field Documentation

◆ $_catalogData

$_catalogData = null
protected

Definition at line 35 of file Output.php.

◆ $_eavConfig

$_eavConfig
protected

Definition at line 42 of file Output.php.

◆ $_escaper

$_escaper
protected

Definition at line 47 of file Output.php.

◆ $_handlers

$_handlers
protected

Definition at line 21 of file Output.php.

◆ $_templateProcessor

$_templateProcessor = null
protected

Definition at line 28 of file Output.php.


The documentation for this class was generated from the following file: