/** * Retrieve files * * @param ThemeInterface $theme * @param string $filePath * @return array|\Magento\Framework\View\File[] * @throws \Magento\Framework\Exception */ public function getFiles(ThemeInterface $theme, $filePath) { $namespace = $module = '*'; $themePath = $theme->getFullPath(); $searchPattern = "{$themePath}/{$namespace}_{$module}/{$this->subDir}*/*/{$filePath}"; $files = $this->themesDirectory->search($searchPattern); if (empty($files)) { return []; } $themes = []; $currentTheme = $theme; while ($currentTheme = $currentTheme->getParentTheme()) { $themes[$currentTheme->getCode()] = $currentTheme; } $result = []; $pattern = "#/(?<module>[^/]+)/{$this->subDir}(?<themeVendor>[^/]+)/(?<themeName>[^/]+)/" . strtr(preg_quote($filePath), ['\\*' => '[^/]+']) . "\$#i"; foreach ($files as $file) { $filename = $this->themesDirectory->getAbsolutePath($file); if (!preg_match($pattern, $filename, $matches)) { continue; } $moduleFull = $matches['module']; $ancestorThemeCode = $matches['themeVendor'] . '/' . $matches['themeName']; if (!isset($themes[$ancestorThemeCode])) { throw new Exception(sprintf("Trying to override modular view file '%s' for theme '%s', which is not ancestor of theme '%s'", $filename, $ancestorThemeCode, $theme->getCode())); } $result[] = $this->fileFactory->create($filename, $moduleFull, $themes[$ancestorThemeCode]); } return $result; }
/** * Retrieve files * * @param ThemeInterface $theme * @param string $filePath * @return array|\Magento\Framework\View\File[] */ public function getFiles(ThemeInterface $theme, $filePath) { $result = []; $namespace = $module = '*'; $sharedFiles = $this->modulesDirectory->search("{$namespace}/{$module}/view/base/{$this->subDir}{$filePath}"); $filePathPtn = strtr(preg_quote($filePath), ['\\*' => '[^/]+']); $pattern = "#(?<namespace>[^/]+)/(?<module>[^/]+)/view/base/{$this->subDir}" . $filePathPtn . "\$#i"; foreach ($sharedFiles as $file) { $filename = $this->modulesDirectory->getAbsolutePath($file); if (!preg_match($pattern, $filename, $matches)) { continue; } $moduleFull = "{$matches['namespace']}_{$matches['module']}"; $result[] = $this->fileFactory->create($filename, $moduleFull, null, true); } $area = $theme->getData('area'); $themeFiles = $this->modulesDirectory->search("{$namespace}/{$module}/view/{$area}/{$this->subDir}{$filePath}"); $pattern = "#(?<namespace>[^/]+)/(?<module>[^/]+)/view/{$area}/{$this->subDir}" . $filePathPtn . "\$#i"; foreach ($themeFiles as $file) { $filename = $this->modulesDirectory->getAbsolutePath($file); if (!preg_match($pattern, $filename, $matches)) { continue; } $moduleFull = "{$matches['namespace']}_{$matches['module']}"; $result[] = $this->fileFactory->create($filename, $moduleFull); } return $result; }
public function testCreate() { $theme = $this->getMockForAbstractClass('Magento\\Framework\\View\\Design\\ThemeInterface'); $file = new \Magento\Framework\View\File(__FILE__, 'Fixture_Module', $theme); $isBase = true; $this->_objectManager->expects($this->once())->method('create')->with('Magento\\Framework\\View\\File', $this->identicalTo(['filename' => __FILE__, 'module' => 'Fixture_Module', 'theme' => $theme, 'isBase' => $isBase]))->will($this->returnValue($file)); $this->assertSame($file, $this->_model->create(__FILE__, 'Fixture_Module', $theme, $isBase)); }
/** * @param ReadInterface $reader * @param ThemeInterface $theme * @param array $files * @return array */ protected function createFiles(ReadInterface $reader, ThemeInterface $theme, $files) { $result = []; foreach ($files as $file) { $filename = $reader->getAbsolutePath($file); $result[] = $this->fileFactory->create($filename, false, $theme); } return $result; }
/** * Retrieve files * * @param ThemeInterface $theme * @param string $filePath * @return array|\Magento\Framework\View\File[] */ public function getFiles(ThemeInterface $theme, $filePath) { $themePath = $theme->getFullPath(); $files = $this->themesDirectory->search("{$themePath}/{$this->subDir}{$filePath}"); $result = []; foreach ($files as $file) { $filename = $this->themesDirectory->getAbsolutePath($file); $result[] = $this->fileFactory->create($filename, null, $theme); } return $result; }
/** * Retrieve files * * @param \Magento\Framework\View\Design\ThemeInterface $theme * @param string $filePath * @return \Magento\Framework\View\File[] */ public function getFiles(ThemeInterface $theme, $filePath) { $result = []; $sharedFiles = $this->componentDirSearch->collectFilesWithContext(ComponentRegistrar::MODULE, "view/base/{$this->subDir}{$filePath}"); foreach ($sharedFiles as $file) { $result[] = $this->fileFactory->create($file->getFullPath(), $file->getComponentName(), null, true); } $area = $theme->getData('area'); $themeFiles = $this->componentDirSearch->collectFilesWithContext(ComponentRegistrar::MODULE, "view/{$area}/{$this->subDir}{$filePath}"); foreach ($themeFiles as $file) { $result[] = $this->fileFactory->create($file->getFullPath(), $file->getComponentName()); } return $result; }
/** * Retrieve files * * @param ThemeInterface $theme * @param string $filePath * @return array|\Magento\Framework\View\File[] */ public function getFiles(ThemeInterface $theme, $filePath) { $namespace = $module = '*'; $themePath = $theme->getFullPath(); $files = $this->themesDirectory->search("{$themePath}/{$namespace}_{$module}/{$this->subDir}{$filePath}"); $result = array(); $pattern = "#/(?<moduleName>[^/]+)/{$this->subDir}" . strtr(preg_quote($filePath), array('\\*' => '[^/]+')) . "\$#i"; foreach ($files as $file) { $filename = $this->themesDirectory->getAbsolutePath($file); if (!preg_match($pattern, $filename, $matches)) { continue; } $result[] = $this->fileFactory->create($filename, $matches['moduleName'], $theme); } return $result; }
/** * Retrieve files * * @param ThemeInterface $theme * @param string $filePath * @return \Magento\Framework\View\File[] */ public function getFiles(ThemeInterface $theme, $filePath) { $namespace = $module = '*'; $themePath = $theme->getFullPath(); if (empty($themePath)) { return []; } $themeAbsolutePath = $this->componentRegistrar->getPath(ComponentRegistrar::THEME, $themePath); if (!$themeAbsolutePath) { return []; } $themeDir = $this->readDirFactory->create($themeAbsolutePath); $searchPattern = "{$namespace}_{$module}/{$this->subDir}{$filePath}"; $files = $themeDir->search($searchPattern); $result = []; $pattern = "#(?<moduleName>[^/]+)/{$this->subDir}" . $this->pathPatternHelper->translatePatternFromGlob($filePath) . "\$#i"; foreach ($files as $file) { $filename = $themeDir->getAbsolutePath($file); if (!preg_match($pattern, $filename, $matches)) { continue; } $result[] = $this->fileFactory->create($filename, $matches['moduleName']); } return $result; }
/** * Get layout files from modules, theme with ancestors and library * * @param ThemeInterface $theme * @param string $filePath * @throws \InvalidArgumentException * @return \Magento\Framework\View\File[] */ public function getFiles(ThemeInterface $theme, $filePath) { if (empty($filePath)) { throw new \InvalidArgumentException('File path must be specified'); } $files = []; if ($this->libDirectory->isExist($filePath)) { $filename = $this->libDirectory->getAbsolutePath($filePath); $files[] = $this->fileFactory->create($filename); } $files = array_merge($files, $this->baseFiles->getFiles($theme, $filePath)); foreach ($theme->getInheritedThemes() as $currentTheme) { $files = array_merge($files, $this->themeModularFiles->getFiles($currentTheme, $filePath)); $files = array_merge($files, $this->themeFiles->getFiles($currentTheme, $filePath)); } return $files; }
/** * Retrieve files * * @param ThemeInterface $theme * @param string $filePath * @return \Magento\Framework\View\File[] * @throws \Magento\Framework\Exception\LocalizedException */ public function getFiles(ThemeInterface $theme, $filePath) { $namespace = $module = '*'; $themePath = $theme->getFullPath(); if (empty($themePath)) { return []; } $themeAbsolutePath = $this->componentRegistrar->getPath(ComponentRegistrar::THEME, $themePath); if (!$themeAbsolutePath) { return []; } $themeDir = $this->readDirFactory->create($themeAbsolutePath); $files = $themeDir->search("{$namespace}_{$module}/{$this->subDir}*/*/{$filePath}"); if (empty($files)) { return []; } $themes = []; $currentTheme = $theme; while ($currentTheme = $currentTheme->getParentTheme()) { $themes[$currentTheme->getCode()] = $currentTheme; } $result = []; $pattern = "#/(?<module>[^/]+)/{$this->subDir}(?<themeVendor>[^/]+)/(?<themeName>[^/]+)/" . $this->pathPatternHelper->translatePatternFromGlob($filePath) . "\$#i"; foreach ($files as $file) { $filename = $themeDir->getAbsolutePath($file); if (!preg_match($pattern, $filename, $matches)) { continue; } $moduleFull = $matches['module']; $ancestorThemeCode = $matches['themeVendor'] . '/' . $matches['themeName']; if (!isset($themes[$ancestorThemeCode])) { throw new LocalizedException(new \Magento\Framework\Phrase("Trying to override modular view file '%1' for theme '%2', which is not ancestor of theme '%3'", [$filename, $ancestorThemeCode, $theme->getCode()])); } $result[] = $this->fileFactory->create($filename, $moduleFull, $themes[$ancestorThemeCode]); } return $result; }