/** * {@inheritdoc} * * @throws \Magento\Framework\Exception */ public function getTheme() { $theme = $this->_themeFactory->create($this->getData('theme_id')); if (!$theme) { throw new \Magento\Framework\Exception('Theme id should be set'); } return $theme; }
/** * Get theme module for custom static files * * @return \Magento\Theme\Model\Theme * @throws \InvalidArgumentException */ protected function _getTheme() { $themeId = $this->_getRequest()->getParam(self::PARAM_THEME_ID); $theme = $this->_themeFactory->create($themeId); if (!$themeId || !$theme) { throw new \InvalidArgumentException('Theme was not found.'); } return $theme; }
/** * Get static file through fallback system using specified params * * @param string $area * @param string|\Magento\Framework\View\Design\ThemeInterface $theme - either theme path (string) or theme object * @param string $locale * @param string $filePath * @param string $module * @param bool $isExplicit * @return bool|string */ private function getStaticFile($area, $theme, $locale, $filePath, $module, $isExplicit = false) { if (!is_object($theme)) { $themePath = $theme ?: $this->getDefaultThemePath($area); $theme = $this->themeRepo->create($themePath, $area); } if ($isExplicit) { $type = \Magento\Framework\View\Design\Fallback\RulePool::TYPE_STATIC_FILE; return $this->explicitFallback->resolve($type, $filePath, $area, $theme, $locale, $module); } return $this->fallback->getFile($area, $theme, $locale, $filePath, $module); }
/** * {@inheritdoc} */ public function getParentTheme() { if ($this->hasData('parent_theme')) { return $this->getData('parent_theme'); } $theme = null; if ($this->getParentId()) { $theme = $this->_themeFactory->create($this->getParentId()); } $this->setParentTheme($theme); return $theme; }
/** * 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; }
/** * Test for the static files fallback according to the themes inheritance * * @param string $file * @param string $themePath * @param string $locale * @param string $module * @param string|null $expectedFilename * * @dataProvider getViewFileDataProvider */ public function testGetViewFile($file, $themePath, $locale, $module, $expectedFilename) { /** @var \Magento\Framework\View\Design\FileResolution\Fallback\StaticFile $model */ $model = Bootstrap::getObjectManager()->create('Magento\\Framework\\View\\Design\\FileResolution\\Fallback\\StaticFile'); $themeModel = $this->themeFactory->create($themePath); $actualFilename = $model->getFile('frontend', $themeModel, $locale, $file, $module); if ($expectedFilename) { $this->assertInternalType('string', $actualFilename); $this->assertStringMatchesFormat($expectedFilename, $actualFilename); $this->assertFileExists($actualFilename); } else { $this->assertFalse($actualFilename); } }
/** * Test for the email template files fallback according to the themes inheritance * * @magentoDataFixture Magento/Store/_files/core_fixturestore.php * @magentoComponentsDir Magento/Email/Model/_files/design * * @param string $file * @param string $themePath * @param string $module * @param string|null $expectedFilename * * @dataProvider getEmailTemplateFileDataProvider */ public function testGetEmailTemplateFile($file, $themePath, $module, $expectedFilename) { $area = \Magento\Framework\App\Area::AREA_FRONTEND; /** @var \Magento\Framework\View\Design\FileResolution\Fallback\EmailTemplateFile $model */ $model = Bootstrap::getObjectManager()->create('Magento\\Framework\\View\\Design\\FileResolution\\Fallback\\EmailTemplateFile'); $themeModel = $this->themeFactory->create($themePath); $locale = \Magento\Setup\Module\I18n\Locale::DEFAULT_SYSTEM_LOCALE; $actualFilename = $model->getFile($area, $themeModel, $locale, $file, $module); if ($expectedFilename) { $this->assertInternalType('string', $actualFilename); $this->assertStringMatchesFormat($expectedFilename, $actualFilename); $this->assertFileExists($actualFilename); } else { $this->assertFalse($actualFilename); } }
/** * @expectedException \InvalidArgumentException * @expectedExceptionMessage Incorrect theme identification key */ public function testNegativeCreate() { $this->factory->create(null); }