@@ -69,6 +69,19 @@ class Inline implements \Magento\Framework\Translate\InlineInterface
69
69
*/
70
70
protected $ state ;
71
71
72
+ /**
73
+ * @var array
74
+ */
75
+ private $ allowedAreas = [
76
+ \Magento \Framework \App \Area::AREA_FRONTEND ,
77
+ \Magento \Framework \App \Area::AREA_ADMINHTML
78
+ ];
79
+
80
+ /**
81
+ * @var \Magento\Framework\App\State
82
+ */
83
+ private $ appState ;
84
+
72
85
/**
73
86
* Initialize inline translation model
74
87
*
@@ -78,6 +91,7 @@ class Inline implements \Magento\Framework\Translate\InlineInterface
78
91
* @param Inline\ConfigInterface $config
79
92
* @param Inline\ParserInterface $parser
80
93
* @param Inline\StateInterface $state
94
+ * @param \Magento\Framework\App\State $appState
81
95
* @param string $templateFileName
82
96
* @param string $translatorRoute
83
97
* @param null $scope
@@ -89,6 +103,7 @@ public function __construct(
89
103
\Magento \Framework \Translate \Inline \ConfigInterface $ config ,
90
104
\Magento \Framework \Translate \Inline \ParserInterface $ parser ,
91
105
\Magento \Framework \Translate \Inline \StateInterface $ state ,
106
+ \Magento \Framework \App \State $ appState ,
92
107
$ templateFileName = '' ,
93
108
$ translatorRoute = '' ,
94
109
$ scope = null
@@ -99,6 +114,7 @@ public function __construct(
99
114
$ this ->config = $ config ;
100
115
$ this ->parser = $ parser ;
101
116
$ this ->state = $ state ;
117
+ $ this ->appState = $ appState ;
102
118
$ this ->templateFileName = $ templateFileName ;
103
119
$ this ->translatorRoute = $ translatorRoute ;
104
120
$ this ->scope = $ scope ;
@@ -115,7 +131,8 @@ public function isAllowed()
115
131
if (!$ this ->scope instanceof \Magento \Framework \App \ScopeInterface) {
116
132
$ scope = $ this ->scopeResolver ->getScope ($ this ->scope );
117
133
}
118
- $ this ->isAllowed = $ this ->config ->isActive ($ scope )
134
+ $ this ->isAllowed = $ this ->isAreaAllowed ()
135
+ && $ this ->config ->isActive ($ scope )
119
136
&& $ this ->config ->isDevAllowed ($ scope );
120
137
}
121
138
return $ this ->state ->isEnabled () && $ this ->isAllowed ;
@@ -249,4 +266,21 @@ protected function stripInlineTranslations(&$body)
249
266
}
250
267
return $ this ;
251
268
}
269
+
270
+ /**
271
+ * Indicates whether the current area is valid for inline translation
272
+ *
273
+ * @return bool
274
+ */
275
+ private function isAreaAllowed ()
276
+ {
277
+ try {
278
+ return in_array (
279
+ $ this ->appState ->getAreaCode (),
280
+ $ this ->allowedAreas
281
+ );
282
+ } catch (\Magento \Framework \Exception \LocalizedException $ e ) {
283
+ return false ;
284
+ }
285
+ }
252
286
}
0 commit comments