/** * Propagate parameters necessary for modular rule basing on module_name parameter * * @param array $params * @return array * @throws \InvalidArgumentException */ public function getPatternDirs(array $params) { if (!array_key_exists('module_name', $params)) { throw new \InvalidArgumentException('Required parameter "module_name" is not specified.'); } $params['module_dir'] = $this->componentRegistrar->getPath(ComponentRegistrar::MODULE, $params['module_name']); return $this->rule->getPatternDirs($params); }
/** * Propagate an underlying fallback rule to every theme in a hierarchy: parent, grandparent, etc. * * @param array $params * @return array * @throws \InvalidArgumentException */ public function getPatternDirs(array $params) { if (!array_key_exists('theme', $params) || !$params['theme'] instanceof ThemeInterface) { throw new \InvalidArgumentException('Parameter "theme" should be specified and should implement the theme interface.'); } $result = array(); /** @var $theme ThemeInterface */ $theme = $params['theme']; unset($params['theme']); while ($theme) { if ($theme->getThemePath()) { $params['theme_path'] = $theme->getThemePath(); $result = array_merge($result, $this->rule->getPatternDirs($params)); } $theme = $theme->getParentTheme(); } return $result; }
/** * Get path of file after using fallback rules * * @param RuleInterface $fallbackRule * @param string $file * @param array $params * @return string|bool */ protected function resolveFile(RuleInterface $fallbackRule, $file, array $params = []) { foreach ($fallbackRule->getPatternDirs($params) as $dir) { $path = "{$dir}/{$file}"; if ($this->rootDirectory->isExist($this->rootDirectory->getRelativePath($path))) { return $path; } } return false; }
/** * Get path of file after using fallback rules * * @param RuleInterface $fallbackRule * @param string $file * @param array $params * @return string|bool */ protected function resolveFile(RuleInterface $fallbackRule, $file, array $params = []) { foreach ($fallbackRule->getPatternDirs($params) as $dir) { $path = "{$dir}/{$file}"; $dirRead = $this->readFactory->create($dir); if ($dirRead->isExist($file)) { return $path; } } return false; }
/** * Return pattern for theme locale directories, where <locale_placeholder> is placed to mark a locale's location. * * @param \Magento\Framework\View\Design\ThemeInterface $theme * @return string * @throws \Exception */ protected static function _getLocalePatternDir(\Magento\Framework\View\Design\ThemeInterface $theme) { $localePlaceholder = '<locale_placeholder>'; $params = array('area' => $theme->getArea(), 'theme' => $theme, 'locale' => $localePlaceholder); $patternDirs = self::$_fallbackRule->getPatternDirs($params); $themePath = '/' . $theme->getFullPath() . '/'; foreach ($patternDirs as $patternDir) { $patternPath = $patternDir . '/'; if (strpos($patternPath, $themePath) !== false && strpos($patternPath, $localePlaceholder) !== false) { return $patternDir; } } throw new \Exception('Unable to determine theme locale path'); }