Пример #1
0
 /**
  * Get CSS files of a given theme
  *
  * Returns an associative array of local assets with FileId used as keys:
  * array('Magento_Catalog::widgets.css' => \Magento\Framework\View\Asset\LocalInterface)
  * The array will be sorted by keys
  *
  * @param \Magento\Framework\View\Design\ThemeInterface $theme
  * @return \Magento\Framework\View\Asset\LocalInterface[]
  */
 public function getCssAssets($theme)
 {
     /** @var $layoutProcessor \Magento\Framework\View\Layout\ProcessorInterface */
     $layoutProcessor = $this->_layoutProcessorFactory->create(['theme' => $theme]);
     $layoutElement = $layoutProcessor->getFileLayoutUpdatesXml();
     /**
      * XPath selector to get CSS files from layout added for HEAD block directly
      */
     $xpathSelectorBlocks = '//block[@class="Magento\\Theme\\Block\\Html\\Head"]' . '/block[@class="Magento\\Theme\\Block\\Html\\Head\\Css"]/arguments/argument[@name="file"]';
     /**
      * XPath selector to get CSS files from layout added for HEAD block using reference
      */
     $xpathSelectorRefs = '//referenceBlock[@name="head"]' . '/block[@class="Magento\\Theme\\Block\\Html\\Head\\Css"]/arguments/argument[@name="file"]';
     $elements = array_merge($layoutElement->xpath($xpathSelectorBlocks) ?: [], $layoutElement->xpath($xpathSelectorRefs) ?: []);
     $params = ['area' => $theme->getArea(), 'themeModel' => $theme];
     $result = [];
     foreach ($elements as $fileId) {
         $fileId = (string) $fileId;
         $result[$fileId] = $this->_assetRepo->createAsset($fileId, $params);
     }
     ksort($result);
     return $result;
 }
Пример #2
0
 /**
  * Generate cache identifier taking into account current area/package/theme/store
  *
  * @param string $suffix
  * @return string
  */
 protected function generateCacheId($suffix = '')
 {
     return "LAYOUT_{$this->theme->getArea()}_STORE{$this->scope->getId()}_{$this->theme->getId()}{$suffix}";
 }
Пример #3
0
 /**
  * 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), array('\\*' => '[^/]+'));
     $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->getArea();
     $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;
 }
Пример #4
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');
 }