Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Design.php
Go to the documentation of this file.
1 <?php
8 
11 
16 {
22  protected $_area;
23 
29  protected $_theme;
30 
37  protected $_callbackFileDir;
38 
44  protected $_storeManager;
45 
49  protected $_flyweightFactory;
50 
54  protected $_themeFactory;
55 
59  private $_scopeConfig;
60 
64  protected $_locale;
65 
69  protected $objectManager;
70 
74  protected $_appState;
75 
85  public function __construct(
87  \Magento\Framework\View\Design\Theme\FlyweightFactory $flyweightFactory,
88  \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
89  \Magento\Theme\Model\ThemeFactory $themeFactory,
90  \Magento\Framework\ObjectManagerInterface $objectManager,
91  \Magento\Framework\App\State $appState,
92  array $themes
93  ) {
94  $this->_storeManager = $storeManager;
95  $this->_flyweightFactory = $flyweightFactory;
96  $this->_themeFactory = $themeFactory;
97  $this->_scopeConfig = $scopeConfig;
98  $this->_appState = $appState;
99  $this->_themes = $themes;
100  $this->objectManager = $objectManager;
101  }
102 
109  public function setArea($area)
110  {
111  $this->_area = $area;
112  $this->_theme = null;
113  return $this;
114  }
115 
121  public function getArea()
122  {
123  // In order to support environment emulation of area, if area is set, return it
124  if ($this->_area && !$this->_appState->isAreaCodeEmulated()) {
125  return $this->_area;
126  }
127  return $this->_appState->getAreaCode();
128  }
129 
137  public function setDesignTheme($theme, $area = null)
138  {
139  if ($area) {
140  $this->setArea($area);
141  } else {
142  $area = $this->getArea();
143  }
144 
145  if ($theme instanceof \Magento\Framework\View\Design\ThemeInterface) {
146  $this->_theme = $theme;
147  } else {
148  $this->_theme = $this->_flyweightFactory->create($theme, $area);
149  }
150 
151  return $this;
152  }
153 
163  public function getConfigurationDesignTheme($area = null, array $params = [])
164  {
165  if (!$area) {
166  $area = $this->getArea();
167  }
168 
169  $theme = null;
170  $store = isset($params['store']) ? $params['store'] : null;
171 
172  if ($this->_isThemePerStoreView($area)) {
173  if ($this->_storeManager->isSingleStoreMode()) {
174  $theme = $this->_scopeConfig->getValue(
175  self::XML_PATH_THEME_ID,
177  );
178  } else {
179  $theme = (string) $this->_scopeConfig->getValue(
180  self::XML_PATH_THEME_ID,
182  $store
183  );
184  }
185  }
186 
187  if (!$theme && isset($this->_themes[$area])) {
188  $theme = $this->_themes[$area];
189  }
190 
191  return $theme;
192  }
193 
200  private function _isThemePerStoreView($area)
201  {
202  return $area == self::DEFAULT_AREA;
203  }
204 
210  public function setDefaultDesignTheme()
211  {
213  return $this;
214  }
215 
221  public function getDesignTheme()
222  {
223  if ($this->_theme === null) {
224  $this->_theme = $this->_themeFactory->create();
225  }
226  return $this->_theme;
227  }
228 
232  public function getThemePath(\Magento\Framework\View\Design\ThemeInterface $theme)
233  {
234  $themePath = $theme->getThemePath();
235  if (!$themePath) {
236  $themeId = $theme->getId();
237  if ($themeId) {
238  $themePath = self::PUBLIC_THEME_DIR . $themeId;
239  } else {
240  $themePath = self::PUBLIC_VIEW_DIR;
241  }
242  }
243  return $themePath;
244  }
245 
251  public function getLocale()
252  {
253  if (null === $this->_locale) {
254  $this->_locale = $this->objectManager->get(\Magento\Framework\Locale\ResolverInterface::class);
255  }
256  return $this->_locale->getLocale();
257  }
258 
263  public function setLocale(\Magento\Framework\Locale\ResolverInterface $locale)
264  {
265  $this->_locale = $locale;
266  return $this;
267  }
268 
272  public function getDesignParams()
273  {
274  $params = [
275  'area' => $this->getArea(),
276  'themeModel' => $this->getDesignTheme(),
277  'locale' => $this->getLocale(),
278  ];
279 
280  return $params;
281  }
282 }
setLocale(\Magento\Framework\Locale\ResolverInterface $locale)
Definition: Design.php:263
$storeManager
__construct(\Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Framework\View\Design\Theme\FlyweightFactory $flyweightFactory, \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, \Magento\Theme\Model\ThemeFactory $themeFactory, \Magento\Framework\ObjectManagerInterface $objectManager, \Magento\Framework\App\State $appState, array $themes)
Definition: Design.php:85
getConfigurationDesignTheme($area=null, array $params=[])
Definition: Design.php:163
getThemePath(\Magento\Framework\View\Design\ThemeInterface $theme)
Definition: Design.php:232
$theme
setDesignTheme($theme, $area=null)
Definition: Design.php:137
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
Definition: website.php:18