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

Public Member Functions

 __construct (\Magento\Framework\App\ScopeResolverInterface $scopeResolver, \Magento\Framework\UrlInterface $url, \Magento\Framework\View\LayoutInterface $layout, \Magento\Framework\Translate\Inline\ConfigInterface $config, \Magento\Framework\Translate\Inline\ParserInterface $parser, \Magento\Framework\Translate\Inline\StateInterface $state, $templateFileName='', $translatorRoute='', $scope=null)
 
 isAllowed ()
 
 getParser ()
 
 processResponseBody (&$body, $isJson=false)
 
 getAdditionalHtmlAttribute ($tagName=null)
 

Protected Member Functions

 addInlineScript ()
 
 getAjaxUrl ()
 
 stripInlineTranslations (&$body)
 

Protected Attributes

 $isAllowed
 
 $parser
 
 $isScriptInserted = false
 
 $url
 
 $layout
 
 $config
 
 $scopeResolver
 
 $templateFileName
 
 $translatorRoute
 
 $scope
 
 $state
 

Detailed Description

Definition at line 11 of file Inline.php.

Constructor & Destructor Documentation

◆ __construct()

Initialize inline translation model

Parameters
\Magento\Framework\App\ScopeResolverInterface$scopeResolver
\Magento\Framework\UrlInterface$url
\Magento\Framework\View\LayoutInterface$layout
Inline\ConfigInterface$config
Inline\ParserInterface$parser
Inline\StateInterface$state
string$templateFileName
string$translatorRoute
null$scope

Definition at line 85 of file Inline.php.

95  {
96  $this->scopeResolver = $scopeResolver;
97  $this->url = $url;
98  $this->layout = $layout;
99  $this->config = $config;
100  $this->parser = $parser;
101  $this->state = $state;
102  $this->templateFileName = $templateFileName;
103  $this->translatorRoute = $translatorRoute;
104  $this->scope = $scope;
105  }

Member Function Documentation

◆ addInlineScript()

addInlineScript ( )
protected

Add inline script code

Insert script and html with added inline translation content.

Returns
void

Definition at line 185 of file Inline.php.

186  {
187  $content = $this->getParser()->getContent();
188  if (stripos($content, '</body>') === false) {
189  return;
190  }
191  if (!$this->isScriptInserted) {
192  $this->getParser()->setContent(str_ireplace('</body>', $this->getInlineScript() . '</body>', $content));
193  $this->isScriptInserted = true;
194  }
195  }

◆ getAdditionalHtmlAttribute()

getAdditionalHtmlAttribute (   $tagName = null)

Additional translation mode html attribute is not needed for base inline translation.

Parameters
mixed | string | null$tagName
Returns
null @SuppressWarnings(PHPMD.UnusedFormalParameter)

Implements InlineInterface.

Definition at line 172 of file Inline.php.

173  {
174  return null;
175  }

◆ getAjaxUrl()

getAjaxUrl ( )
protected

Return URL for ajax requests

Returns
string

Definition at line 221 of file Inline.php.

222  {
223  return $this->url->getUrl(
224  $this->translatorRoute,
225  ['_secure' => $this->scopeResolver->getScope()->isCurrentlySecure()]
226  );
227  }

◆ getParser()

getParser ( )

Retrieve Inline Parser instance

Returns
Inline\ParserInterface

Implements InlineInterface.

Definition at line 129 of file Inline.php.

130  {
131  return $this->parser;
132  }

◆ isAllowed()

isAllowed ( )

Check if Inline Translates is allowed

Returns
bool

Implements InlineInterface.

Definition at line 112 of file Inline.php.

113  {
114  if ($this->isAllowed === null) {
115  if (!$this->scope instanceof \Magento\Framework\App\ScopeInterface) {
116  $scope = $this->scopeResolver->getScope($this->scope);
117  }
118  $this->isAllowed = $this->config->isActive($scope)
119  && $this->config->isDevAllowed($scope);
120  }
121  return $this->state->isEnabled() && $this->isAllowed;
122  }

◆ processResponseBody()

processResponseBody ( $body,
  $isJson = false 
)

Replace translation templates with HTML fragments

Parameters
array | string&$body
bool$isJson
Returns
$this

Implements InlineInterface.

Definition at line 141 of file Inline.php.

142  {
143  if (!$this->isAllowed()) {
144  $this->stripInlineTranslations($body);
145  return $this;
146  }
147 
148  $this->getParser()->setIsJson($isJson);
149 
150  if (is_array($body)) {
151  foreach ($body as &$part) {
152  $this->processResponseBody($part, $isJson);
153  }
154  } elseif (is_string($body)) {
155  $this->getParser()->processResponseBodyString($body);
156  $this->addInlineScript();
157  $body = $this->getParser()->getContent();
158  }
159 
160  $this->getParser()->setIsJson(false);
161 
162  return $this;
163  }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
processResponseBody(&$body, $isJson=false)
Definition: Inline.php:141

◆ stripInlineTranslations()

stripInlineTranslations ( $body)
protected

Strip inline translations from text

Parameters
array | string&$body
Returns
$this

Definition at line 235 of file Inline.php.

236  {
237  if (is_array($body)) {
238  foreach ($body as &$part) {
239  $this->stripInlineTranslations($part);
240  }
241  } else {
242  if (is_string($body)) {
243  $body = preg_replace(
244  '#' . \Magento\Framework\Translate\Inline\ParserInterface::REGEXP_TOKEN . '#',
245  '$1',
246  $body
247  );
248  }
249  }
250  return $this;
251  }

Field Documentation

◆ $config

$config
protected

Definition at line 45 of file Inline.php.

◆ $isAllowed

$isAllowed
protected

Definition at line 18 of file Inline.php.

◆ $isScriptInserted

$isScriptInserted = false
protected

Definition at line 30 of file Inline.php.

◆ $layout

$layout
protected

Definition at line 40 of file Inline.php.

◆ $parser

$parser
protected

Definition at line 23 of file Inline.php.

◆ $scope

$scope
protected

Definition at line 65 of file Inline.php.

◆ $scopeResolver

$scopeResolver
protected

Definition at line 50 of file Inline.php.

◆ $state

$state
protected

Definition at line 70 of file Inline.php.

◆ $templateFileName

$templateFileName
protected

Definition at line 55 of file Inline.php.

◆ $translatorRoute

$translatorRoute
protected

Definition at line 60 of file Inline.php.

◆ $url

$url
protected

Definition at line 35 of file Inline.php.


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