public function testGetThemes() { $this->registrar->expects($this->once())->method('getPaths')->with(ComponentRegistrar::THEME)->willReturn(['theme1' => 'path1', 'theme2' => 'path2']); $themePackage = $this->getMock('\\Magento\\Framework\\View\\Design\\Theme\\ThemePackage', [], [], '', false); $this->factory->expects($this->exactly(2))->method('create')->withConsecutive(['theme1', 'path1'], ['theme2', 'path2'])->willReturn($themePackage); $actual = $this->object->getThemes(); $this->assertCount(2, $actual); foreach ($actual as $themePackage) { $this->assertSame($themePackage, $themePackage); } }
/** * Find all theme-based email templates for a given template ID * * @param string $templateId * @return array[] */ public function getThemeTemplates($templateId) { $templates = []; $area = $this->getTemplateArea($templateId); $module = $this->getTemplateModule($templateId); $filename = $this->_getInfo($templateId, 'file'); foreach ($this->themePackages->getThemes() as $theme) { if ($theme->getArea() == $area) { $themeDir = $this->readDirFactory->create($theme->getPath()); $file = "{$module}/email/{$filename}"; if ($themeDir->isExist($file)) { $templates[] = ['value' => sprintf('%s/%s/%s', $templateId, $theme->getVendor(), $theme->getName()), 'label' => sprintf('%s (%s/%s)', $this->getTemplateLabel($templateId), $theme->getVendor(), $theme->getName()), 'group' => $this->getTemplateModule($templateId)]; } } } return $templates; }
/** * Fill collection with theme model loaded from filesystem * * @param bool $printQuery * @param bool $logQuery * @return $this * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function loadData($printQuery = false, $logQuery = false) { if ($this->isLoaded()) { return $this; } $themes = []; foreach ($this->themePackageList->getThemes() as $themePackage) { if ($this->isAcceptable(self::CONSTRAINT_AREA, $themePackage->getArea()) && $this->isAcceptable(self::CONSTRAINT_VENDOR, $themePackage->getVendor()) && $this->isAcceptable(self::CONSTRAINT_THEME_NAME, $themePackage->getName())) { $themes[] = $themePackage; } } $this->_loadFromFilesystem($themes); $this->resetConstraints(); $this->_updateRelations()->_renderFilters()->_clearFilters(); return $this; }
/** * Collect templates from themes * * @param bool $withMetaInfo * @param array $result * @return void */ private function accumulateThemeTemplateFiles($withMetaInfo, array &$result) { foreach ($this->themePackageList->getThemes() as $theme) { $files = []; $this->_accumulateFilesByPatterns([$theme->getPath() . '/*_*/templates'], '*.phtml', $files); if ($withMetaInfo) { $regex = '#^' . str_replace(DIRECTORY_SEPARATOR, '/', $theme->getPath()) . '/(?P<module>[a-z\\d]+_[a-z\\d]+)/templates/(?P<path>.+)$#i'; foreach ($files as $file) { if (preg_match($regex, $file, $matches)) { $result[] = [$theme->getArea(), $theme->getVendor() . '/' . $theme->getName(), $matches['module'], $matches['path'], $file]; } else { echo $regex . " - " . $file . "\n"; throw new \UnexpectedValueException("Could not parse theme template file '{$file}'"); } } } else { $result = array_merge($result, $files); } } }