123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282 |
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- namespace Magento\Theme\Model\View;
- use Magento\Framework\App\Config\ScopeConfigInterface;
- use Magento\Store\Model\ScopeInterface;
- /**
- * Keeps design settings for current request
- */
- class Design implements \Magento\Framework\View\DesignInterface
- {
- /**
- * Package area
- *
- * @var string
- */
- protected $_area;
- /**
- * Package theme
- *
- * @var \Magento\Theme\Model\Theme
- */
- protected $_theme;
- /**
- * Directory of the css file
- * Using only to transmit additional parameter in callback functions
- *
- * @var string
- */
- protected $_callbackFileDir;
- /**
- * Store list manager
- *
- * @var \Magento\Store\Model\StoreManagerInterface
- */
- protected $_storeManager;
- /**
- * @var \Magento\Framework\View\Design\Theme\FlyweightFactory
- */
- protected $_flyweightFactory;
- /**
- * @var \Magento\Theme\Model\ThemeFactory
- */
- protected $_themeFactory;
- /**
- * @var \Magento\Framework\App\Config\ScopeConfigInterface
- */
- private $_scopeConfig;
- /**
- * @var \Magento\Framework\Locale\ResolverInterface
- */
- protected $_locale;
- /**
- * @var \Magento\Framework\ObjectManagerInterface
- */
- protected $objectManager;
- /**
- * @var \Magento\Framework\App\State
- */
- protected $_appState;
- /**
- * @param \Magento\Store\Model\StoreManagerInterface $storeManager
- * @param \Magento\Framework\View\Design\Theme\FlyweightFactory $flyweightFactory
- * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
- * @param \Magento\Theme\Model\ThemeFactory $themeFactory
- * @param \Magento\Framework\ObjectManagerInterface $objectManager
- * @param \Magento\Framework\App\State $appState
- * @param array $themes
- */
- public function __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
- ) {
- $this->_storeManager = $storeManager;
- $this->_flyweightFactory = $flyweightFactory;
- $this->_themeFactory = $themeFactory;
- $this->_scopeConfig = $scopeConfig;
- $this->_appState = $appState;
- $this->_themes = $themes;
- $this->objectManager = $objectManager;
- }
- /**
- * Set package area
- *
- * @param string $area
- * @return $this
- */
- public function setArea($area)
- {
- $this->_area = $area;
- $this->_theme = null;
- return $this;
- }
- /**
- * Retrieve package area
- *
- * @return string
- */
- public function getArea()
- {
- // In order to support environment emulation of area, if area is set, return it
- if ($this->_area && !$this->_appState->isAreaCodeEmulated()) {
- return $this->_area;
- }
- return $this->_appState->getAreaCode();
- }
- /**
- * Set theme path
- *
- * @param \Magento\Framework\View\Design\ThemeInterface|string $theme
- * @param string $area
- * @return $this
- */
- public function setDesignTheme($theme, $area = null)
- {
- if ($area) {
- $this->setArea($area);
- } else {
- $area = $this->getArea();
- }
- if ($theme instanceof \Magento\Framework\View\Design\ThemeInterface) {
- $this->_theme = $theme;
- } else {
- $this->_theme = $this->_flyweightFactory->create($theme, $area);
- }
- return $this;
- }
- /**
- * Get default theme which declared in configuration
- *
- * Write default theme to core_config_data
- *
- * @param string|null $area
- * @param array $params
- * @return string|int
- */
- public function getConfigurationDesignTheme($area = null, array $params = [])
- {
- if (!$area) {
- $area = $this->getArea();
- }
- $theme = null;
- $store = isset($params['store']) ? $params['store'] : null;
- if ($this->_isThemePerStoreView($area)) {
- if ($this->_storeManager->isSingleStoreMode()) {
- $theme = $this->_scopeConfig->getValue(
- self::XML_PATH_THEME_ID,
- ScopeInterface::SCOPE_WEBSITES
- );
- } else {
- $theme = (string) $this->_scopeConfig->getValue(
- self::XML_PATH_THEME_ID,
- ScopeInterface::SCOPE_STORE,
- $store
- );
- }
- }
- if (!$theme && isset($this->_themes[$area])) {
- $theme = $this->_themes[$area];
- }
- return $theme;
- }
- /**
- * Whether themes in specified area are supposed to be configured per store view
- *
- * @param string $area
- * @return bool
- */
- private function _isThemePerStoreView($area)
- {
- return $area == self::DEFAULT_AREA;
- }
- /**
- * Set default design theme
- *
- * @return $this
- */
- public function setDefaultDesignTheme()
- {
- $this->setDesignTheme($this->getConfigurationDesignTheme());
- return $this;
- }
- /**
- * Design theme model getter
- *
- * @return \Magento\Theme\Model\Theme
- */
- public function getDesignTheme()
- {
- if ($this->_theme === null) {
- $this->_theme = $this->_themeFactory->create();
- }
- return $this->_theme;
- }
- /**
- * {@inheritdoc}
- */
- public function getThemePath(\Magento\Framework\View\Design\ThemeInterface $theme)
- {
- $themePath = $theme->getThemePath();
- if (!$themePath) {
- $themeId = $theme->getId();
- if ($themeId) {
- $themePath = self::PUBLIC_THEME_DIR . $themeId;
- } else {
- $themePath = self::PUBLIC_VIEW_DIR;
- }
- }
- return $themePath;
- }
- /**
- * Get locale
- *
- * @return string
- */
- public function getLocale()
- {
- if (null === $this->_locale) {
- $this->_locale = $this->objectManager->get(\Magento\Framework\Locale\ResolverInterface::class);
- }
- return $this->_locale->getLocale();
- }
- /**
- * @param \Magento\Framework\Locale\ResolverInterface $locale
- * @return $this
- */
- public function setLocale(\Magento\Framework\Locale\ResolverInterface $locale)
- {
- $this->_locale = $locale;
- return $this;
- }
- /**
- * {@inheritdoc}
- */
- public function getDesignParams()
- {
- $params = [
- 'area' => $this->getArea(),
- 'themeModel' => $this->getDesignTheme(),
- 'locale' => $this->getLocale(),
- ];
- return $params;
- }
- }
|