コード例 #1
0
ファイル: Repository.php プロジェクト: pavelnovitsky/magento2
 /**
  * Update required parameters with default values if custom not specified
  *
  * @param array &$params
  * @throws \UnexpectedValueException
  * @return $this
  *
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 public function updateDesignParams(array &$params)
 {
     $defaults = $this->design->getDesignParams();
     // Set area
     if (empty($params['area'])) {
         $params['area'] = $defaults['area'];
     }
     // Set themeModel
     $theme = null;
     $area = $params['area'];
     if (!empty($params['themeId'])) {
         $theme = $params['themeId'];
     } elseif (isset($params['theme'])) {
         $theme = $params['theme'];
     } elseif (empty($params['themeModel']) && $area !== $defaults['area']) {
         $theme = $this->design->getConfigurationDesignTheme($area);
     }
     if ($theme) {
         $params['themeModel'] = $this->themeList->getThemeByFullPath($area . '/' . $theme);
         if (!$params['themeModel']) {
             throw new \UnexpectedValueException("Could not find theme '{$theme}' for area '{$area}'");
         }
     } elseif (empty($params['themeModel'])) {
         $params['themeModel'] = $defaults['themeModel'];
     }
     // Set module
     if (!array_key_exists('module', $params)) {
         $params['module'] = false;
     }
     // Set locale
     if (empty($params['locale'])) {
         $params['locale'] = $defaults['locale'];
     }
     return $this;
 }
コード例 #2
0
 /**
  * Retrieve instance of a theme currently used in an area
  *
  * @return \Magento\Framework\View\Design\ThemeInterface
  */
 public function get()
 {
     $area = $this->appState->getAreaCode();
     if ($this->design->getDesignTheme()->getArea() == $area || $this->design->getArea() == $area) {
         return $this->design->getDesignTheme();
     }
     /** @var \Magento\Theme\Model\ResourceModel\Theme\Collection $themeCollection */
     $themeCollection = $this->themeFactory->create();
     $themeIdentifier = $this->design->getConfigurationDesignTheme($area);
     if (is_numeric($themeIdentifier)) {
         $result = $themeCollection->getItemById($themeIdentifier);
     } else {
         $themeFullPath = $area . \Magento\Framework\View\Design\ThemeInterface::PATH_SEPARATOR . $themeIdentifier;
         $result = $themeCollection->getThemeByFullPath($themeFullPath);
     }
     return $result;
 }
コード例 #3
0
 /**
  * @magentoConfigFixture current_store design/theme/theme_id one
  * @magentoConfigFixture fixturestore_store design/theme/theme_id two
  * @magentoDataFixture Magento/Core/_files/store.php
  */
 public function testGetConfigurationDesignThemeStore()
 {
     $storeId = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\\Framework\\StoreManagerInterface')->getStore()->getId();
     $this->assertEquals('one', $this->_model->getConfigurationDesignTheme());
     $this->assertEquals('one', $this->_model->getConfigurationDesignTheme(null, array('store' => $storeId)));
     $this->assertEquals('one', $this->_model->getConfigurationDesignTheme('frontend', array('store' => $storeId)));
     $this->assertEquals('two', $this->_model->getConfigurationDesignTheme(null, array('store' => 'fixturestore')));
     $this->assertEquals('two', $this->_model->getConfigurationDesignTheme('frontend', array('store' => 'fixturestore')));
 }
コード例 #4
0
 /**
  * @magentoConfigFixture current_store design/theme/theme_id one
  * @magentoDataFixture Magento/Store/_files/core_fixturestore.php
  */
 public function testGetConfigurationDesignThemeStore()
 {
     $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
     /** @var \Magento\Framework\App\Config\MutableScopeConfigInterface $mutableConfig */
     $mutableConfig = $objectManager->get('Magento\\Framework\\App\\Config\\MutableScopeConfigInterface');
     $mutableConfig->setValue('design/theme/theme_id', 'two', ScopeInterface::SCOPE_STORE, 'fixturestore');
     $storeId = $objectManager->get('Magento\\Store\\Model\\StoreManagerInterface')->getStore()->getId();
     $this->assertEquals('one', $this->_model->getConfigurationDesignTheme());
     $this->assertEquals('one', $this->_model->getConfigurationDesignTheme(null, ['store' => $storeId]));
     $this->assertEquals('one', $this->_model->getConfigurationDesignTheme('frontend', ['store' => $storeId]));
     $this->assertEquals('two', $this->_model->getConfigurationDesignTheme(null, ['store' => 'fixturestore']));
     $this->assertEquals('two', $this->_model->getConfigurationDesignTheme('frontend', ['store' => 'fixturestore']));
 }
コード例 #5
0
 /**
  * Get a default theme path for specified area
  *
  * @param string $area
  * @return string
  * @throws \LogicException
  */
 private function getDefaultThemePath($area)
 {
     switch ($area) {
         case 'frontend':
             return $this->design->getConfigurationDesignTheme($area);
         case 'adminhtml':
             return 'Magento/backend';
         case 'install':
             return 'Magento/basic';
         default:
             throw new \LogicException('Unable to determine theme path');
     }
 }
コード例 #6
0
 /**
  * Get configuration theme id
  *
  * @param \Magento\Store\Model\Store $store
  * @return int
  */
 protected function _getConfigurationThemeId($store)
 {
     return $this->_design->getConfigurationDesignTheme(\Magento\Framework\App\Area::AREA_FRONTEND, array('store' => $store));
 }