示例#1
0
 /**
  * Get directory where themes files are stored
  *
  * @param \Magento\Framework\View\Design\ThemeInterface $theme
  * @return string|null
  */
 public function getThemeFilesPath(\Magento\Framework\View\Design\ThemeInterface $theme)
 {
     $path = null;
     if ($theme->getFullPath()) {
         $path = $this->themeDirectoryRead->getAbsolutePath($theme->getFullPath());
     }
     return $path;
 }
示例#2
0
 /**
  * Get directory where themes files are stored
  *
  * @param \Magento\Framework\View\Design\ThemeInterface $theme
  * @return string|null
  */
 public function getThemeFilesPath(\Magento\Framework\View\Design\ThemeInterface $theme)
 {
     $path = null;
     if ($theme->getFullPath()) {
         $path = $this->componentRegistrar->getPath(ComponentRegistrar::THEME, $theme->getFullPath());
     }
     return $path;
 }
示例#3
0
 /**
  * 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;
 }
示例#4
0
 /**
  * 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;
 }
示例#5
0
 /**
  * Calculate unique identifier for a view file
  *
  * @return string
  */
 public function getFileIdentifier()
 {
     if (null === $this->identifier) {
         $theme = $this->getTheme() ? '|theme:' . $this->theme->getFullPath() : '';
         $this->identifier = ($this->isBase ? 'base' : '') . $theme . '|module:' . $this->getModule() . '|file:' . $this->getName();
     }
     return $this->identifier;
 }
示例#6
0
 /**
  * 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;
 }
示例#7
0
 /**
  * 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;
 }
示例#8
0
 /**
  * Retrieve files
  *
  * @param \Magento\Framework\View\Design\ThemeInterface $theme
  * @param string $filePath
  * @return \Magento\Framework\View\File[]
  */
 public function getFiles(ThemeInterface $theme, $filePath)
 {
     $namespace = $module = '*';
     $themePath = $theme->getFullPath();
     $files = $this->directory->search("{$themePath}/{$namespace}_{$module}/{$this->subDir}{$filePath}");
     $result = [];
     $pattern = "#/(?<moduleName>[^/]+)/{$this->subDir}"
         . $this->pathPatternHelper->translatePatternFromGlob($filePath) . "$#i";
     foreach ($files as $file) {
         $filename = $this->directory->getAbsolutePath($file);
         if (!preg_match($pattern, $filename, $matches)) {
             continue;
         }
         $result[] = $this->fileFactory->create($filename, $matches['moduleName'], $theme);
     }
     return $result;
 }
示例#9
0
 /**
  * Retrieve files
  *
  * @param ThemeInterface $theme
  * @param string $filePath
  * @return \Magento\Framework\View\File[]
  * @throws \UnexpectedValueException
  */
 public function getFiles(ThemeInterface $theme, $filePath)
 {
     $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($this->subDir . $filePath);
     $result = [];
     foreach ($files as $file) {
         $filename = $themeDir->getAbsolutePath($file);
         $result[] = $this->fileFactory->create($filename, null, $theme);
     }
     return $result;
 }
示例#10
0
    /**
     * Retrieve files
     *
     * @param \Magento\Framework\View\Design\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();
        $searchPattern = "{$themePath}/{$namespace}_{$module}/{$this->subDir}*/*/{$filePath}";
        $files = $this->directory->search($searchPattern);

        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 = $this->directory->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;
    }
示例#11
0
 /**
  * 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');
 }
示例#12
0
 /**
  * Checks that a theme present in filesystem collection
  *
  * @param ThemeInterface $theme
  * @return bool
  */
 public function hasTheme(ThemeInterface $theme)
 {
     $themeItems = $this->getItems();
     return $theme->getThemePath() && isset($themeItems[$theme->getFullPath()]);
 }
示例#13
0
 /**
  * Add theme to shared collection
  *
  * @param \Magento\Framework\View\Design\ThemeInterface $themeModel
  * @return $this
  */
 protected function _addTheme(\Magento\Framework\View\Design\ThemeInterface $themeModel)
 {
     if ($themeModel->getId()) {
         $this->themes[$themeModel->getId()] = $themeModel;
         $themePath = $themeModel->getFullPath();
         if ($themePath) {
             $this->themesByPath[$themePath] = $themeModel;
         }
     }
     return $this;
 }