public function testGenerateLessFileTree() { $originalContent = 'original content'; $expectedContent = 'updated content'; $expectedRelativePath = 'view_preprocessed/less/some/file.less'; $expectedPath = '/var/view_preprocessed/less/some/file.less'; $asset = $this->getMock('\\Magento\\Framework\\View\\Asset\\File', array(), array(), '', false); $asset->expects($this->once())->method('getPath')->will($this->returnValue('some/file.css')); $chain = new \Magento\Framework\View\Asset\PreProcessor\Chain($asset, $originalContent, 'less'); $this->magentoImport->expects($this->once())->method('process')->with($chain); $this->import->expects($this->once())->method('process')->with($chain); $relatedAssetOne = $this->getMock('\\Magento\\Framework\\View\\Asset\\File', array(), array(), '', false); $relatedAssetOne->expects($this->any())->method('getPath')->will($this->returnValue('related/file_one.css')); $relatedAssetOne->expects($this->any())->method('getContent')->will($this->returnValue("content of 'related/file_one.css'")); $relatedAssetTwo = $this->getMock('\\Magento\\Framework\\View\\Asset\\File', array(), array(), '', false); $relatedAssetTwo->expects($this->any())->method('getPath')->will($this->returnValue('related/file_two.css')); $relatedAssetTwo->expects($this->any())->method('getContent')->will($this->returnValue("content of 'related/file_two.css'")); $assetsMap = [['related/file_one.css', $asset, $relatedAssetOne], ['related/file_two.css', $asset, $relatedAssetTwo]]; $this->assetRepo->expects($this->any())->method('createRelated')->will($this->returnValueMap($assetsMap)); $relatedFilesOne = [['related/file_one.css', $asset]]; $this->import->expects($this->at(1))->method('getRelatedFiles')->will($this->returnValue($relatedFilesOne)); $relatedFilesTwo = [['related/file_two.css', $asset]]; $this->import->expects($this->at(3))->method('getRelatedFiles')->will($this->returnValue($relatedFilesTwo)); $this->import->expects($this->at(5))->method('getRelatedFiles')->will($this->returnValue([])); $writeMap = [[$expectedRelativePath, $expectedContent], ['related/file_one.css', "content of 'related/file_one.css'"], ['related/file_two.css', "content of 'related/file_two.css'"]]; $pathsMap = [[$expectedRelativePath, $expectedPath], ['related/file_one.css', '/var/view_preprocessed/less/related/file_one.css'], ['related/file_two.css', '/var/view_preprocessed/less/related/file_two.css']]; $this->tmpDirectory->expects($this->any())->method('writeFile')->will($this->returnValueMap($writeMap)); $this->tmpDirectory->expects($this->any())->method('getAbsolutePath')->will($this->returnValueMap($pathsMap)); $actual = $this->object->generateLessFileTree($chain); $this->assertSame($expectedPath, $actual); }
/** * Get file path by type * * @param string $type * @param \Magento\Framework\View\Design\ThemeInterface $theme * @return string * @throws \Magento\Framework\Exception */ protected function _getFilePathByType($type, $theme) { if (!isset($this->_fileNames[$type])) { throw new \Magento\Framework\Exception("Unknown control configuration type: \"{$type}\""); } return $this->assetRepo->createAsset($this->_fileNames[$type], ['area' => \Magento\Framework\View\DesignInterface::DEFAULT_AREA, 'themeModel' => $theme])->getSourceFile(); }
/** * @param \Magento\Framework\RequireJs\Config\File\Collector\Aggregated $fileSource * @param \Magento\Framework\View\DesignInterface $design * @param \Magento\Framework\Filesystem $appFilesystem * @param \Magento\Framework\View\Asset\Repository $assetRepo */ public function __construct(\Magento\Framework\RequireJs\Config\File\Collector\Aggregated $fileSource, \Magento\Framework\View\DesignInterface $design, \Magento\Framework\Filesystem $appFilesystem, \Magento\Framework\View\Asset\Repository $assetRepo) { $this->fileSource = $fileSource; $this->design = $design; $this->baseDir = $appFilesystem->getDirectoryRead(DirectoryList::ROOT); $this->staticContext = $assetRepo->getStaticViewFileContext(); }
/** * @param string $assetRelPath * @param string $relatedFieldId * @param string $similarRelPath * @param string $expectedResult * @dataProvider convertModuleNotationToPathModularSeparatorDataProvider */ public function testConvertModuleNotationToPathModularSeparator($assetRelPath, $relatedFieldId, $similarRelPath, $expectedResult) { $similarAsset = $this->getMock('Magento\\Framework\\View\\Asset\\File', [], [], '', false); $similarAsset->expects($this->any())->method('getPath')->will($this->returnValue($similarRelPath)); $this->asset->expects($this->once())->method('getPath')->will($this->returnValue($assetRelPath)); $this->assetRepo->expects($this->once())->method('createSimilar')->with($relatedFieldId, $this->asset)->will($this->returnValue($similarAsset)); $this->assertEquals($expectedResult, $this->object->convertModuleNotationToPath($this->asset, $relatedFieldId)); }
public function testGetTranslationFilePath() { $path = 'path'; $contextMock = $this->getMockForAbstractClass('\\Magento\\Framework\\View\\Asset\\ContextInterface', [], '', true, true, true, ['getPath']); $this->assetRepoMock->expects($this->atLeastOnce())->method('getStaticViewFileContext')->willReturn($contextMock); $contextMock->expects($this->atLeastOnce())->method('getPath')->willReturn($path); $this->assertEquals($path, $this->model->getTranslationFilePath()); }
/** * @param bool $isSecure * @dataProvider getViewFileUrlDataProvider */ public function testGetViewFileUrl($isSecure) { $this->request->expects($this->once())->method('isSecure')->will($this->returnValue($isSecure)); $this->assetRepo->expects($this->once())->method('getUrlWithParams')->with('some file', $this->callback(function ($value) use($isSecure) { return isset($value['_secure']) && $value['_secure'] === $isSecure; }))->will($this->returnValue('result url')); $this->assertEquals('result url', $this->model->getViewFileUrl('some file')); }
/** * @param string $content * @return void */ public function updateTranslationFileContent($content) { $translationDir = $this->directoryList->getPath(DirectoryList::STATIC_VIEW) . \DIRECTORY_SEPARATOR . $this->assetRepo->getStaticViewFileContext()->getPath(); if (!$this->driverFile->isExists($this->getTranslationFileFullPath())) { $this->driverFile->createDirectory($translationDir); } $this->driverFile->filePutContents($this->getTranslationFileFullPath(), $content); }
/** * @param string $content * @return void */ public function updateTranslationFileContent($content) { $translationDir = $this->directoryList->getPath(DirectoryList::STATIC_VIEW) . \DIRECTORY_SEPARATOR . $this->assetRepo->getStaticViewFileContext()->getPath(); if (!$this->driverFile->isExists($this->getTranslationFileFullPath())) { $this->driverFile->createDirectory($translationDir, \Magento\Framework\Filesystem\Driver\File::WRITEABLE_DIRECTORY_MODE); } $this->driverFile->filePutContents($this->getTranslationFileFullPath(), $content); }
protected function setUp() { $baseUrl = 'http://example.com/pub/static/'; $path = 'frontend/Magento/blank/en_US'; $this->context = $this->getMock('\\Magento\\Framework\\View\\Asset\\File\\Context', null, [$baseUrl, DirectoryList::STATIC_VIEW, $path]); $this->assetRepo = $this->getMock('Magento\\Framework\\View\\Asset\\Repository', [], [], '', false); $this->assetRepo->expects($this->any())->method('getStaticViewFileContext')->will($this->returnValue($this->context)); $this->object = new \Magento\Framework\View\Asset\NotationResolver\Variable($this->assetRepo); }
/** * Injecting less.js compiler * * @param array $resultGroups * * @return mixed */ private function renderLessJsScripts($resultGroups) { // less js have to be injected before any *.js in developer mode $lessJsConfigAsset = $this->assetRepo->createAsset('less/config.less.js'); $resultGroups['js'] .= sprintf('<script src="%s"></script>' . "\n", $lessJsConfigAsset->getUrl()); $lessJsAsset = $this->assetRepo->createAsset('less/less.min.js'); $resultGroups['js'] .= sprintf('<script src="%s"></script>' . "\n", $lessJsAsset->getUrl()); return $resultGroups; }
/** * Retrieve url of a view file * * @param string $fileId * @param array $params * @return string */ public function getViewFileUrl($fileId, array $params = []) { try { $params = array_merge(['_secure' => $this->_request->isSecure()], $params); return $this->_assetRepo->getUrlWithParams($fileId, $params); } catch (\Magento\Framework\Exception\LocalizedException $e) { return ''; } }
/** * Retrieves the value of a given placeholder * * @param string $placeholder * @return string */ public function getPlaceholderValue($placeholder) { $context = $this->assetRepo->getStaticViewFileContext(); switch ($placeholder) { case self::VAR_BASE_URL_PATH: return $context->getBaseUrl() . $context->getPath(); default: return ''; } }
public function testGetTemplateFileName() { $params = array('area' => 'some_area', 'themeModel' => $this->getMock('Magento\\Framework\\View\\Design\\ThemeInterface', array(), array(), '', false, false), 'module' => 'Some_Module'); $file = 'Some_Module::some_file.ext'; $expected = 'path/to/some_file.ext'; $this->_templateFileResolution->expects($this->once())->method('getFile')->with($params['area'], $params['themeModel'], 'some_file.ext', 'Some_Module')->will($this->returnValue($expected)); $this->_assetRepo->expects($this->any())->method('extractScope')->with($file, $params)->will($this->returnValue('some_file.ext')); $actual = $this->_model->getTemplateFileName($file, $params); $this->assertEquals($expected, $actual); }
public function testCreateTranslateConfigAsset() { $path = 'relative path'; $expectedPath = $path . '/' . FileManager::TRANSLATION_CONFIG_FILE_NAME; $fileMock = $this->getMock('\\Magento\\Framework\\View\\Asset\\File', [], [], '', false); $contextMock = $this->getMockForAbstractClass('\\Magento\\Framework\\View\\Asset\\ContextInterface', [], '', true, true, true, ['getPath']); $this->assetRepoMock->expects($this->once())->method('getStaticViewFileContext')->willReturn($contextMock); $contextMock->expects($this->once())->method('getPath')->willReturn($path); $this->assetRepoMock->expects($this->once())->method('createArbitrary')->with($expectedPath, '')->willReturn($fileMock); $this->assertSame($fileMock, $this->model->createTranslateConfigAsset()); }
/** * Convert module notation to a path relative to the specified asset * * For example, the asset is Foo_Bar/styles/style.css and it refers to Bar_Baz::images/logo.gif * (i.e. url(Bar_Baz::images/logo.gif)) * The result will be ../../Bar_Baz/images/logo.gif * * @param Asset\LocalInterface $thisAsset * @param string $relatedFileId * @return string */ public function convertModuleNotationToPath(Asset\LocalInterface $thisAsset, $relatedFileId) { if (false === strpos($relatedFileId, Asset\Repository::FILE_ID_SEPARATOR)) { return $relatedFileId; } $thisPath = $thisAsset->getPath(); $relatedAsset = $this->assetRepo->createSimilar($relatedFileId, $thisAsset); $relatedPath = $relatedAsset->getPath(); $offset = FileSystem::offsetPath($relatedPath, $thisPath); return FileSystem::normalizePath($offset . '/' . basename($relatedPath)); }
public function testCreateRequireJsAssetDevMode() { $this->config->expects($this->once())->method('getConfigFileRelativePath')->will($this->returnValue('requirejs/file.js')); $this->fileSystem->expects($this->once())->method('getDirectoryWrite')->with(DirectoryList::STATIC_VIEW)->will($this->returnValue($this->dir)); $this->assetRepo->expects($this->once())->method('createArbitrary')->with('requirejs/file.js', '')->will($this->returnValue($this->asset)); $this->appState->expects($this->once())->method('getMode')->will($this->returnValue(\Magento\Framework\App\State::MODE_DEVELOPER)); $this->dir->expects($this->never())->method('isExist'); $data = 'requirejs config data'; $this->config->expects($this->once())->method('getConfig')->will($this->returnValue($data)); $this->dir->expects($this->once())->method('writeFile')->with('requirejs/file.js', $data); $this->assertSame($this->asset, $this->object->createRequireJsConfigAsset()); }
/** * Render view config object for current package and theme * * @param array $params * @return \Magento\Framework\Config\View */ public function getViewConfig(array $params = []) { $this->assetRepo->updateDesignParams($params); /** @var $currentTheme \Magento\Framework\View\Design\ThemeInterface */ $currentTheme = $params['themeModel']; $key = $currentTheme->getCode(); if (isset($this->viewConfigs[$key])) { return $this->viewConfigs[$key]; } $config = $this->viewConfigFactory->create(); $this->viewConfigs[$key] = $config; return $config; }
public function getViewFileUrlWithException() { $params = ['a' => 'b']; $paramsSecure = ['a' => 'b', '_secure' => false]; $fileId = 'file id'; $fileUrl = 'exception url'; $this->requestMock->expects($this->once())->method('isSecure')->willReturn(false); $exception = new LocalizedException('message'); $this->repositoryMock->expects($this->once())->method('getUrlWithParams')->with($fileId, $paramsSecure)->willThrowException($exception); $this->loggerMock->expects($this->once())->method('critical')->with($exception); $this->urlMock->expects($this->once())->method('getUrl')->with('', ['_direct' => 'core/index/notFound'])->willReturn($fileUrl); $this->assertEquals($fileUrl, $this->model->getViewFileUrl($fileId, $params)); }
/** * Run test for execute method */ public function testExecute() { /** @var OutputInterface|\PHPUnit_Framework_MockObject_MockObject $outputMock */ $outputMock = $this->getMockBuilder(OutputInterface::class)->getMockForAbstractClass(); $assetMock = $this->getMockBuilder(LocalInterface::class)->getMockForAbstractClass(); $this->validatorMock->expects(self::once())->method('isValid')->with(self::LOCALE_TEST_VALUE)->willReturn(true); $message = sprintf('<info>Processed Area: %s, Locale: %s, Theme: %s, File type: %s.</info>', self::AREA_TEST_VALUE, self::LOCALE_TEST_VALUE, self::THEME_TEST_VALUE, self::TYPE_TEST_VALUE); $outputMock->expects(self::at(0))->method('writeln')->with($message); $outputMock->expects(self::at(1))->method('writeln')->with('<comment>-> file-test-value/test/file</comment>'); $outputMock->expects(self::at(2))->method('writeln')->with('<info>Successfully processed.</info>'); $this->assetRepositoryMock->expects(self::once())->method('createAsset')->with('file-test-value/test' . DIRECTORY_SEPARATOR . 'file' . '.' . self::TYPE_TEST_VALUE, ['area' => self::AREA_TEST_VALUE, 'theme' => self::THEME_TEST_VALUE, 'locale' => self::LOCALE_TEST_VALUE])->willReturn($assetMock); $this->assetPublisherMock->expects(self::once())->method('publish')->with($assetMock); $assetMock->expects(self::once())->method('getFilePath')->willReturn(self::FILE_TEST_VALUE); $this->sourceThemeDeployCommand->run($this->getInputMock(), $outputMock); }
public function testExecute() { $file = 'css/styles-m' . '.less'; $this->configLoader->expects($this->once())->method('load')->with('frontend')->willReturn([]); $this->objectManager->expects($this->once())->method('configure'); $this->sourceFileGeneratorPool->expects($this->once())->method('create')->with('less')->willReturn($this->getMock('Magento\\Framework\\Less\\FileGenerator', [], [], '', false)); $this->assetRepo->expects($this->once())->method('createAsset')->with($file, ['area' => 'frontend', 'theme' => 'Magento/blank', 'locale' => 'en_US'])->willReturn($this->getMockForAbstractClass('Magento\\Framework\\View\\Asset\\LocalInterface')); $this->assetSource->expects($this->once())->method('findSource')->willReturn('/dev/null'); $this->chainFactory->expects($this->once())->method('create')->willReturn($this->getMock('Magento\\Framework\\View\\Asset\\PreProcessor\\Chain', [], [], '', false)); $this->filesystem->expects($this->atLeastOnce())->method('getDirectoryWrite')->willReturn($this->getMock('\\Magento\\Framework\\Filesystem\\Directory\\WriteInterface', [], [], '', false)); $this->validator->expects($this->once())->method('isValid')->with('en_US')->willReturn(true); $commandTester = new CommandTester($this->command); $commandTester->execute(['type' => 'less']); $this->assertContains('Successfully processed LESS and/or SASS files', $commandTester->getDisplay()); }
public function testGetDefaultEmailLogo() { $model = $this->getModelMock(); $value = 'urlWithParamsValue'; $this->assetRepo->method('getUrlWithParams')->with('Magento_Email::logo_email.png', ['area' => \Magento\Framework\App\Area::AREA_FRONTEND])->will($this->returnValue($value)); $this->assertEquals($value, $model->getDefaultEmailLogo()); }
/** * @return File */ public function build() { $params = ['area' => $this->area, 'theme' => $this->theme, 'locale' => $this->locale, 'module' => $this->module]; $asset = $this->repository->createAsset($this->path, $params); unset($this->path, $this->module, $this->locale, $this->theme, $this->area); return $asset; }
/** * Render view config object for current package and theme * * @param array $params * @return \Magento\Framework\Config\View */ public function getViewConfig(array $params = []) { $this->assetRepo->updateDesignParams($params); /** @var $currentTheme \Magento\Framework\View\Design\ThemeInterface */ $currentTheme = $params['themeModel']; $key = $currentTheme->getCode(); if (isset($this->viewConfigs[$key])) { return $this->viewConfigs[$key]; } $configFiles = $this->moduleReader->getConfigurationFiles(basename($this->filename))->toArray(); $themeConfigFile = $currentTheme->getCustomization()->getCustomViewConfigPath(); if (empty($themeConfigFile) || !$this->rootDirectory->isExist($this->rootDirectory->getRelativePath($themeConfigFile)) ) { $themeConfigFile = $this->viewFileSystem->getFilename($this->filename, $params); } if ($themeConfigFile && $this->rootDirectory->isExist($this->rootDirectory->getRelativePath($themeConfigFile)) ) { $configFiles[$this->rootDirectory->getRelativePath($themeConfigFile)] = $this->rootDirectory->readFile( $this->rootDirectory->getRelativePath($themeConfigFile) ); } $config = $this->viewFactory->create($configFiles); $this->viewConfigs[$key] = $config; return $config; }
/** * {@inheritdoc} * @throws \InvalidArgumentException */ protected function execute(InputInterface $input, OutputInterface $output) { $locale = $input->getOption(self::LOCALE_OPTION); if (!$this->validator->isValid($locale)) { throw new \InvalidArgumentException($locale . ' argument has invalid value, please run info:language:list for list of available locales'); } $area = $input->getOption(self::AREA_OPTION); $theme = $input->getOption(self::THEME_OPTION); $type = $input->getArgument(self::TYPE_ARGUMENT); $this->state->setAreaCode($area); $this->objectManager->configure($this->configLoader->load($area)); $sourceFileGenerator = $this->sourceFileGeneratorPool->create($type); foreach ($input->getArgument(self::FILE_ARGUMENT) as $file) { $file .= '.' . $type; $output->writeln("<info>Gathering {$file} sources.</info>"); $asset = $this->assetRepo->createAsset($file, ['area' => $area, 'theme' => $theme, 'locale' => $locale]); $rootDir = $this->filesystem->getDirectoryWrite(DirectoryList::ROOT); $sourceFile = $this->assetSource->findSource($asset); $relativePath = $rootDir->getRelativePath($sourceFile); $content = $rootDir->readFile($relativePath); $chain = $this->chainFactory->create(['asset' => $asset, 'origContent' => $content, 'origContentType' => $asset->getContentType(), 'origAssetPath' => $relativePath]); $processedCoreFile = $sourceFileGenerator->generateFileTree($chain); $targetDir = $this->filesystem->getDirectoryWrite(DirectoryList::STATIC_VIEW); $source = $rootDir->getRelativePath($processedCoreFile); $destination = $asset->getPath(); $rootDir->copyFile($source, $destination, $targetDir); $output->writeln("<info>Successfully processed dynamic stylesheet into CSS</info>"); } }
/** * {@inheritdoc} * @throws \InvalidArgumentException */ protected function execute(InputInterface $input, OutputInterface $output) { $area = $input->getOption(self::AREA_OPTION); $locale = $input->getOption(self::LOCALE_OPTION); $theme = $input->getOption(self::THEME_OPTION); $type = $input->getOption(self::TYPE_ARGUMENT); $files = $input->getArgument(self::FILE_ARGUMENT); if (!$this->validator->isValid($locale)) { throw new \InvalidArgumentException($locale . ' argument has invalid value, please run info:language:list for list of available locales'); } if (!preg_match('#^[\\w\\-]+\\/[\\w\\-]+$#', $theme)) { throw new \InvalidArgumentException('Value "' . $theme . '" of the option "' . self::THEME_OPTION . '" has invalid format. The format should be "Vendor/theme".'); } $message = sprintf('<info>Processed Area: %s, Locale: %s, Theme: %s, File type: %s.</info>', $area, $locale, $theme, $type); $output->writeln($message); foreach ($files as $file) { $fileInfo = pathinfo($file); $asset = $this->assetRepository->createAsset($fileInfo['dirname'] . DIRECTORY_SEPARATOR . $fileInfo['basename'] . '.' . $type, ['area' => $area, 'theme' => $theme, 'locale' => $locale]); try { $this->assetPublisher->publish($asset); } catch (\Magento\Framework\View\Asset\File\NotFoundException $e) { throw new \InvalidArgumentException('Verify entered values of the argument and options. ' . $e->getMessage()); } $output->writeln('<comment>-> ' . $asset->getFilePath() . '</comment>'); } $output->writeln('<info>Successfully processed.</info>'); }
/** * Finds requested resource and provides it to the client * * @return \Magento\Framework\App\ResponseInterface * @throws \Exception */ public function launch() { $appMode = $this->state->getMode(); if ($appMode == \Magento\Framework\App\State::MODE_PRODUCTION) { $this->response->setHttpResponseCode(404); } else { try { $path = $this->request->get('resource'); $params = $this->parsePath($path); $this->state->setAreaCode($params['area']); $this->objectManager->configure($this->configLoader->load($params['area'])); $file = $params['file']; unset($params['file']); $asset = $this->assetRepo->createAsset($file, $params); $this->response->setFilePath($asset->getSourceFile()); $this->publisher->publish($asset); } catch (\Exception $e) { if ($appMode == \Magento\Framework\App\State::MODE_DEVELOPER) { throw $e; } $this->response->setHttpResponseCode(404); } } return $this->response; }
public function testCreateMinResolverAsset() { $this->configMock->expects($this->any())->method('getMinResolverRelativePath')->willReturn('relative path'); $this->assetRepoMock->expects($this->once())->method('createArbitrary')->with('relative path'); $this->fileSystem->expects($this->once())->method('getDirectoryWrite')->with(DirectoryList::STATIC_VIEW)->will($this->returnValue($this->dir)); $this->object->createMinResolverAsset(); }
/** * Deploy a static view file * * @param string $filePath * @param string $area * @param string $themePath * @param string $locale * @param string $module * @return void */ private function deployFile($filePath, $area, $themePath, $locale, $module) { $requestedPath = $filePath; if (substr($filePath, -5) == '.less') { $requestedPath = preg_replace('/.less$/', '.css', $filePath); } $logMessage = "Processing file '{$filePath}' for area '{$area}', theme '{$themePath}', locale '{$locale}'"; if ($module) { $logMessage .= ", module '{$module}'"; } $this->logger->logDebug($logMessage); try { $asset = $this->assetRepo->createAsset($requestedPath, ['area' => $area, 'theme' => $themePath, 'locale' => $locale, 'module' => $module]); $asset = $this->minifyService->getAssets([$asset], true)[0]; $this->logger->logDebug("\tDeploying the file to '{$asset->getPath()}'", '.'); if ($this->isDryRun) { $asset->getContent(); } else { $this->assetPublisher->publish($asset); $this->bundleManager->addAsset($asset); } $this->count++; } catch (\Magento\Framework\View\Asset\File\NotFoundException $e) { // File was not found by Fallback (possibly because it's wrong context for it) - there is nothing to publish $this->logger->logDebug("\tNotice: Could not find file '{$filePath}'. This file may not be relevant for the theme or area."); } catch (\Less_Exception_Compiler $e) { $this->logger->logDebug("\tNotice: Could not parse LESS file '{$filePath}'. " . "This may indicate that the file is incomplete, but this is acceptable. " . "The file '{$filePath}' will be combined with another LESS file."); } catch (\Exception $e) { $this->logger->logError($e->getMessage() . " ({$logMessage})"); $this->logger->logDebug((string) $e); $this->errorCount++; } }
/** * Return element html code * * @return string */ public function getElementHtml() { $htmlId = $this->_escaper->escapeHtml($this->getHtmlId()); $uploadUrl = $this->_escaper->escapeHtml($this->_getUploadUrl()); $spacerImage = $this->_assetRepo->getUrl('images/spacer.gif'); $imagePlaceholderText = __('Click here or drag and drop to add images'); $deleteImageText = __('Delete image'); $makeBaseText = __('Make Base'); $hiddenText = __('Hidden'); $imageManagementText = __('Image Management'); /** @var $product \Magento\Catalog\Model\Product */ $html = <<<HTML <div id="{$htmlId}-container" class="images" data-mage-init='{"baseImage":{}}' data-max-file-size="{$this->_getFileMaxSize()}" > <div class="image image-placeholder"> <input type="file" name="image" data-url="{$uploadUrl}" multiple="multiple" /> <img class="spacer" src="{$spacerImage}"/> <p class="image-placeholder-text">{$imagePlaceholderText}</p> </div> <script id="{$htmlId}-template" class="image-template" type="text/x-jquery-tmpl"> <div class="image"> <img class="spacer" src="{$spacerImage}"/> <img class="product-image" src="\${url}" data-position="\${position}" alt="\${label}" /> <div class="actions"> <button class="action-delete" data-role="delete-button" title="{$deleteImageText}"> <span>{$deleteImageText}</span> </button> <button class="action-make-base" data-role="make-base-button" title="{$makeBaseText}"> <span>{$makeBaseText}</span> </button> <div class="draggable-handle"></div> </div> <div class="image-label"></div> <div class="image-fade"><span>{$hiddenText}</span></div> </div> </script> </div> <span class="action-manage-images" data-activate-tab="image-management"> <span>{$imageManagementText}</span> </span> <script> require([ 'jquery' ],function(\$){ 'use strict'; \$('[data-activate-tab=image-management]') .on('click.toggleImageManagementTab', function() { \$('#product_info_tabs_image-management').trigger('click'); }); }); </script> HTML; return $html; }
/** * Remove all bundles from pool * * @return bool */ public function clearBundleJsPool() { $dirWrite = $this->filesystem->getDirectoryWrite(DirectoryList::STATIC_VIEW); /** @var $context \Magento\Framework\View\Asset\File\FallbackContext */ $context = $this->assetRepo->getStaticViewFileContext(); $bundleDir = $context->getPath() . '/' . Config::BUNDLE_JS_DIR; return $dirWrite->delete($bundleDir); }