Skip to content
Snippets Groups Projects
Commit 98ea60e7 authored by Joan He's avatar Joan He
Browse files

MAGETWO-38207: move includeDirective() down inheritance chain

parent b6654abb
Branches
No related merge requests found
......@@ -110,6 +110,13 @@ class Filter extends \Magento\Framework\Filter\Template
*/
protected $backendUrlBuilder;
/**
* Include processor
*
* @var callable|null
*/
protected $_includeProcessor = null;
/**
* @param \Magento\Framework\Stdlib\String $string
* @param \Psr\Log\LoggerInterface $logger
......@@ -216,6 +223,49 @@ class Filter extends \Magento\Framework\Filter\Template
return $this->_storeId;
}
/**
* @param string[] $construction
* @return mixed
*/
public function includeDirective($construction)
{
// Processing of {include template=... [...]} statement
$includeParameters = $this->_getIncludeParameters($construction[2]);
if (!isset($includeParameters['template']) or !$this->getIncludeProcessor()) {
// Not specified template or not set include processor
$replacedValue = '{Error in include processing}';
} else {
// Including of template
$templateCode = $includeParameters['template'];
unset($includeParameters['template']);
$includeParameters = array_merge_recursive($includeParameters, $this->_templateVars);
$replacedValue = call_user_func($this->getIncludeProcessor(), $templateCode, $includeParameters);
}
return $replacedValue;
}
/**
* Sets the processor of includes.
*
* @param callable $callback it must return string
* @return $this
*/
public function setIncludeProcessor(array $callback)
{
$this->_includeProcessor = $callback;
return $this;
}
/**
* Sets the processor of includes.
*
* @return callable|null
*/
public function getIncludeProcessor()
{
return is_callable($this->_includeProcessor) ? $this->_includeProcessor : null;
}
/**
* Retrieve Block html directive
*
......
......@@ -32,13 +32,6 @@ class Template implements \Zend_Filter_Interface
*/
protected $_templateVars = [];
/**
* Include processor
*
* @var callable|null
*/
protected $_includeProcessor = null;
/**
* @var \Magento\Framework\Stdlib\String
*/
......@@ -68,28 +61,6 @@ class Template implements \Zend_Filter_Interface
return $this;
}
/**
* Sets the processor of includes.
*
* @param callable $callback it must return string
* @return $this
*/
public function setIncludeProcessor(array $callback)
{
$this->_includeProcessor = $callback;
return $this;
}
/**
* Sets the processor of includes.
*
* @return callable|null
*/
public function getIncludeProcessor()
{
return is_callable($this->_includeProcessor) ? $this->_includeProcessor : null;
}
/**
* Filter the string as template.
*
......@@ -153,27 +124,6 @@ class Template implements \Zend_Filter_Interface
return $replacedValue;
}
/**
* @param string[] $construction
* @return mixed
*/
public function includeDirective($construction)
{
// Processing of {include template=... [...]} statement
$includeParameters = $this->_getIncludeParameters($construction[2]);
if (!isset($includeParameters['template']) or !$this->getIncludeProcessor()) {
// Not specified template or not set include processor
$replacedValue = '{Error in include processing}';
} else {
// Including of template
$templateCode = $includeParameters['template'];
unset($includeParameters['template']);
$includeParameters = array_merge_recursive($includeParameters, $this->_templateVars);
$replacedValue = call_user_func($this->getIncludeProcessor(), $templateCode, $includeParameters);
}
return $replacedValue;
}
/**
* @param string[] $construction
* @return string
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment