/**
  * Apply customized static files to frontend
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return void
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     /** @var $themeFile \Magento\Theme\Model\Theme\File */
     foreach ($this->currentTheme->getCustomization()->getFiles() as $themeFile) {
         try {
             $service = $themeFile->getCustomizationService();
             if ($service instanceof \Magento\Framework\View\Design\Theme\Customization\FileAssetInterface) {
                 $identifier = $themeFile->getData('file_path');
                 $dirPath = \Magento\Framework\View\Design\Theme\Customization\Path::DIR_NAME . '/' . $this->currentTheme->getId();
                 $asset = $this->assetRepo->createArbitrary($identifier, $dirPath, DirectoryList::MEDIA, \Magento\Framework\UrlInterface::URL_TYPE_MEDIA);
                 $this->pageAssets->add($identifier, $asset);
             }
         } catch (\InvalidArgumentException $e) {
             $this->logger->critical($e);
         }
     }
 }
示例#2
0
 /**
  * @return void
  */
 public function testCreateArbitrary()
 {
     $contextMock = $this->getMockBuilder('Magento\\Framework\\View\\Asset\\ContextInterface')->disableOriginalConstructor()->getMock();
     $this->contextFactoryMock->expects($this->once())->method('create')->with(['baseUrl' => '', 'baseDirType' => 'dirType', 'contextPath' => 'dir/path'])->willReturn($contextMock);
     $assetMock = $this->getMockBuilder('Magento\\Framework\\View\\Asset\\File')->disableOriginalConstructor()->getMock();
     $this->fileFactoryMock->expects($this->once())->method('create')->with(['source' => $this->sourceMock, 'context' => $contextMock, 'filePath' => 'test/file.js', 'module' => '', 'contentType' => ''])->willReturn($assetMock);
     $this->assertEquals($assetMock, $this->repository->createArbitrary('test/file.js', 'dir/path', 'dirType', 'static'));
 }
示例#3
0
 /**
  * Create an asset object for merged file
  *
  * @param array $assets
  * @return MergeableInterface
  */
 private function createMergedAsset(array $assets)
 {
     $paths = array();
     /** @var MergeableInterface $asset */
     foreach ($assets as $asset) {
         $paths[] = $asset->getPath();
     }
     $paths = array_unique($paths);
     $filePath = md5(implode('|', $paths)) . '.' . $this->contentType;
     return $this->assetRepo->createArbitrary($filePath, self::getRelativeDir());
 }
 /**
  * @param string $filePath
  * @param string $dirPath
  * @param string $baseUrlType
  * @param string $expectedType
  * @param string $expectedUrl
  * @dataProvider createArbitraryDataProvider
  */
 public function testCreateArbitrary($filePath, $dirPath, $baseUrlType, $expectedType, $expectedUrl)
 {
     $this->baseUrl->expects($this->once())->method('getBaseUrl')->will($this->returnValueMap([[['_type' => 'static'], 'http://example.com/static/'], [['_type' => 'media'], 'http://example.com/media/']]));
     $dirType = 'dirType';
     $asset = $this->object->createArbitrary($filePath, $dirPath, $dirType, $baseUrlType);
     $this->assertInstanceOf('\\Magento\\Framework\\View\\Asset\\File', $asset);
     $this->assertEquals($expectedType, $asset->getContentType());
     $this->assertEquals($expectedUrl, $asset->getUrl());
     $this->assertEquals($dirType, $asset->getContext()->getBaseDirType());
     $anotherAsset = $this->object->createArbitrary('another/path.js', $dirPath, $dirType, $baseUrlType);
     $this->assertSame($anotherAsset->getContext(), $asset->getContext());
 }
示例#5
0
 /**
  * Create a view assets representing the bundle js functionality
  *
  * @return \Magento\Framework\View\Asset\File[]
  */
 public function createBundleJsPool()
 {
     $bundles = [];
     if ($this->appState->getMode() == AppState::MODE_PRODUCTION) {
         $libDir = $this->filesystem->getDirectoryRead(DirectoryList::STATIC_VIEW);
         /** @var $context \Magento\Framework\View\Asset\File\FallbackContext */
         $context = $this->assetRepo->getStaticViewFileContext();
         $bundleDir = $context->getPath() . '/' . Config::BUNDLE_JS_DIR;
         if (!$libDir->isExist($bundleDir)) {
             return [];
         }
         foreach ($libDir->read($bundleDir) as $bundleFile) {
             $relPath = $libDir->getRelativePath($bundleFile);
             $bundles[] = $this->assetRepo->createArbitrary($relPath, '');
         }
     }
     return $bundles;
 }
示例#6
0
 /**
  * Create a view asset representing the requirejs config.config property for inline translation
  *
  * @return \Magento\Framework\View\Asset\File
  */
 public function createTranslateConfigAsset()
 {
     return $this->assetRepo->createArbitrary($this->assetRepo->getStaticViewFileContext()->getPath() . '/' . self::TRANSLATION_CONFIG_FILE_NAME, '');
 }
示例#7
0
 /**
  * Create a view asset representing the aggregated configuration file
  *
  * @return \Magento\Framework\View\Asset\File
  */
 public function createRequireJsAsset()
 {
     $relPath = $this->config->getConfigFileRelativePath();
     $this->ensureSourceFile($relPath);
     return $this->assetRepo->createArbitrary($relPath, '');
 }