/** * @param FallbackContext $assetContext * @return \Magento\Framework\Config\View */ public function getConfig(FallbackContext $assetContext) { $themePath = $assetContext->getAreaCode() . '/' . $assetContext->getThemePath(); if (!isset($this->config[$themePath])) { $this->config[$themePath] = $this->viewConfig->getViewConfig(['area' => $assetContext->getAreaCode(), 'themeModel' => $this->getThemeProvider()->getThemeByFullPath($themePath)]); } return $this->config[$themePath]; }
/** * Preparation of content for the destination file * * @param string $path * @param string $content * @param string $module * @param FallbackContext $context * @return string * @throws \UnexpectedValueException */ private function processContent($path, $content, $module, FallbackContext $context) { if ($this->alternativesSorted === null) { $this->alternativesSorted = $this->sorter->sort($this->alternatives); } $path = $this->filenameResolver->resolve($path); foreach ($this->alternativesSorted as $name => $alternative) { $asset = $this->assetBuilder->setArea($context->getAreaCode())->setTheme($context->getThemePath())->setLocale($context->getLocale())->setModule($module)->setPath(preg_replace('#\\.' . preg_quote(pathinfo($path, PATHINFO_EXTENSION)) . '$#', '.' . $name, $path))->build(); $processor = $this->objectManager->get($alternative[self::PROCESSOR_CLASS]); if (!$processor instanceof ContentProcessorInterface) { throw new \UnexpectedValueException('"' . $alternative[self::PROCESSOR_CLASS] . '" has to implement the ContentProcessorInterface.'); } $content = $processor->processContent($asset); if (trim($content) !== '') { return $content; } } return $content; }
/** * Find asset file via fallback mechanism * * @param LocalInterface $asset * @param \Magento\Framework\View\Asset\File\FallbackContext $context * @return bool|string */ private function findFileThroughFallback(LocalInterface $asset, \Magento\Framework\View\Asset\File\FallbackContext $context) { $themeModel = $this->themeList->getThemeByFullPath($context->getAreaCode() . '/' . $context->getThemePath()); $sourceFile = $this->fallback->getFile($context->getAreaCode(), $themeModel, $context->getLocale(), $asset->getFilePath(), $asset->getModule()); return $sourceFile; }
/** * @param FallbackContext $assetContext * @return \Magento\Framework\Config\View */ public function getConfig(FallbackContext $assetContext) { return $this->viewConfig->getViewConfig(['area' => $assetContext->getAreaCode(), 'themeModel' => $this->themeList->getThemeByFullPath($assetContext->getAreaCode() . '/' . $assetContext->getThemePath())]); }
/** * @covers \Magento\Framework\View\Asset\File\FallbackContext::getConfigPath * @param string $baseUrl * @param string $areaType * @param string $themePath * @param string $localeCode * @param bool $isSecure * @param string $expectedResult * @dataProvider getConfigPathDataProvider */ public function testGetConfigPath($baseUrl, $areaType, $themePath, $localeCode, $isSecure, $expectedResult) { $this->fallbackContext = $this->objectManager->getObject('Magento\\Framework\\View\\Asset\\File\\FallbackContext', ['baseUrl' => $baseUrl, 'areaType' => $areaType, 'themePath' => $themePath, 'localeCode' => $localeCode, 'isSecure' => $isSecure]); $this->assertEquals($expectedResult, $this->fallbackContext->getConfigPath()); }
/** * Preparation of content for the destination file * * @param string $path * @param string $content * @param string $module * @param FallbackContext $context * @return string */ private function processContent($path, $content, $module, FallbackContext $context) { foreach ($this->alternativeSource->getAlternativesExtensionsNames() as $name) { $asset = $this->assetBuilder->setArea($context->getAreaCode())->setTheme($context->getThemePath())->setLocale($context->getLocale())->setModule($module)->setPath(preg_replace('#\\.' . preg_quote(pathinfo($path, PATHINFO_EXTENSION)) . '$#', '.' . $name, $path))->build(); $processedContent = $this->assetSource->getContent($asset); if (trim($processedContent) !== '') { return $processedContent; } } return $content; }