/** * Add necessary options * * @return \Magento\Framework\View\Element\AbstractBlock */ protected function _beforeToHtml() { if (!$this->getOptions()) { $layoutMergeParams = array('theme' => $this->_getThemeInstance($this->getTheme())); /** @var $layoutProcessor \Magento\Framework\View\Layout\ProcessorInterface */ $layoutProcessor = $this->_layoutProcessorFactory->create($layoutMergeParams); $layoutProcessor->addPageHandles(array($this->getLayoutHandle())); $layoutProcessor->addPageHandles(array('default')); $layoutProcessor->load(); $containers = $layoutProcessor->getContainers(); if ($this->getAllowedContainers()) { foreach (array_keys($containers) as $containerName) { if (!in_array($containerName, $this->getAllowedContainers())) { unset($containers[$containerName]); } } } asort($containers, SORT_STRING); $this->addOption('', __('-- Please Select --')); foreach ($containers as $containerName => $containerLabel) { $this->addOption($containerName, $containerLabel); } } return parent::_beforeToHtml(); }
/** * Retrieve the layout update instance * * @return \Magento\Framework\View\Layout\ProcessorInterface */ protected function getPageLayoutMerge() { if ($this->pageLayoutMerge) { return $this->pageLayoutMerge; } $this->pageLayoutMerge = $this->processorFactory->create(['theme' => $this->themeResolver->get(), 'fileSource' => $this->pageLayoutFileSource, 'cacheSuffix' => self::MERGE_CACHE_SUFFIX]); return $this->pageLayoutMerge; }
public function testGetUpdate() { $themeMock = $this->getMockForAbstractClass('Magento\\Framework\\View\\Design\\ThemeInterface'); $this->themeResolverMock->expects($this->once())->method('get')->will($this->returnValue($themeMock)); $this->processorFactoryMock->expects($this->once())->method('create')->with(array('theme' => $themeMock))->will($this->returnValue($this->processorMock)); $this->assertEquals($this->processorMock, $this->_model->getUpdate()); $this->assertEquals($this->processorMock, $this->_model->getUpdate()); }
public function testRead() { $data = 'test_string'; $xml = '<body> <attribute name="body_attribute_name" value="body_attribute_value" /> </body>'; $this->processorInterface->expects($this->any())->method('load')->with($data)->will($this->returnValue($this->processorInterface)); $this->themeResolver->expects($this->atLeastOnce())->method('get')->will($this->returnValue($this->themeInterface)); $createData = ['theme' => $this->themeInterface, 'fileSource' => $this->pageLayoutFileSource, 'cacheSuffix' => 'page_layout']; $this->processorFactory->expects($this->once())->method('create')->with($createData)->will($this->returnValue($this->processorInterface)); $element = new \Magento\Framework\View\Layout\Element($xml); $this->processorInterface->expects($this->once())->method('asSimplexml')->will($this->returnValue($element)); $this->readerPool->expects($this->once())->method('interpret')->with($this->readerContext, $element); $this->model->read($this->readerContext, $data); }
public function testGenerateElementsWithCache() { $layoutCacheId = 'layout_cache_id'; /** @var \Magento\Framework\View\Layout\Element $xml */ $xml = simplexml_load_string('<layout/>', 'Magento\Framework\View\Layout\Element'); $this->model->setXml($xml); $themeMock = $this->getMockForAbstractClass('Magento\Framework\View\Design\ThemeInterface'); $this->themeResolverMock->expects($this->once()) ->method('get') ->willReturn($themeMock); $this->processorFactoryMock->expects($this->once()) ->method('create') ->with(['theme' => $themeMock]) ->willReturn($this->processorMock); $this->processorMock->expects($this->once()) ->method('getCacheId') ->willReturn($layoutCacheId); $readerContextMock = $this->getMockBuilder('Magento\Framework\View\Layout\Reader\Context') ->disableOriginalConstructor() ->getMock(); $this->cacheMock->expects($this->once()) ->method('load') ->with('structure_' . $layoutCacheId) ->willReturn(serialize($readerContextMock)); $this->readerPoolMock->expects($this->never()) ->method('interpret'); $this->cacheMock->expects($this->never()) ->method('save'); $generatorContextMock = $this->getMockBuilder('Magento\Framework\View\Layout\Generator\Context') ->disableOriginalConstructor() ->getMock(); $this->generatorContextFactoryMock->expects($this->once()) ->method('create') ->with(['structure' => $this->structureMock, 'layout' => $this->model]) ->willReturn($generatorContextMock); $this->generatorPoolMock->expects($this->once()) ->method('process') ->with($readerContextMock, $generatorContextMock) ->willReturn(true); $elements = [ 'name_1' => ['type' => '', 'parent' => null], 'name_2' => ['type' => \Magento\Framework\View\Layout\Element::TYPE_CONTAINER, 'parent' => null], 'name_3' => ['type' => '', 'parent' => 'parent'], 'name_4' => ['type' => \Magento\Framework\View\Layout\Element::TYPE_CONTAINER, 'parent' => 'parent'], ]; $this->structureMock->expects($this->once()) ->method('exportElements') ->willReturn($elements); $this->model->generateElements(); }
/** * Retrieve the layout update instance * * @return \Magento\Framework\View\Layout\ProcessorInterface */ public function getUpdate() { if (!$this->_update) { $theme = $this->themeResolver->get(); $this->_update = $this->_processorFactory->create(['theme' => $theme]); } return $this->_update; }
public function testGenerateXml() { $themeMock = $this->getMockForAbstractClass('Magento\\Framework\\View\\Design\\ThemeInterface'); $this->themeResolverMock->expects($this->once())->method('get')->will($this->returnValue($themeMock)); $this->processorFactoryMock->expects($this->once())->method('create')->with(['theme' => $themeMock])->will($this->returnValue($this->processorMock)); $xmlString = '<?xml version="1.0"?><layout xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">' . '<some_update>123</some_update></layout>'; $xml = simplexml_load_string($xmlString, 'Magento\\Framework\\View\\Layout\\Element'); $this->processorMock->expects($this->once())->method('asSimplexml')->will($this->returnValue($xml)); $this->structureMock->expects($this->once())->method('importElements')->with($this->equalTo([]))->will($this->returnSelf()); $this->assertSame($this->model, $this->model->generateXml()); $this->assertSame('<some_update>123</some_update>', $this->model->getNode('some_update')->asXml()); }
/** * 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; }
/** * Add design abstractions information to the options * * @param array $designAbstractions * @return void */ protected function _addDesignAbstractionOptions(array $designAbstractions) { $label = array(); // Sort list of design abstractions by label foreach ($designAbstractions as $key => $row) { $label[$key] = $row['label']; } array_multisort($label, SORT_STRING, $designAbstractions); // Group the layout options $customLayouts = array(); $pageLayouts = array(); /** @var $layoutProcessor \Magento\Framework\View\Layout\ProcessorInterface */ $layoutProcessor = $this->_layoutProcessorFactory->create(); foreach ($designAbstractions as $pageTypeName => $pageTypeInfo) { if ($layoutProcessor->isPageLayoutDesignAbstraction($pageTypeInfo)) { $pageLayouts[] = array('value' => $pageTypeName, 'label' => $pageTypeInfo['label']); } else { $customLayouts[] = array('value' => $pageTypeName, 'label' => $pageTypeInfo['label']); } } $params = array(); $this->addOption($customLayouts, __('Custom Layouts'), $params); $this->addOption($pageLayouts, __('Page Layouts'), $params); }