/** * Initialize dependencies */ protected function setUp() { $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); $objectManager->get('Magento\\Framework\\App\\State')->setAreaCode(\Magento\Framework\View\DesignInterface::DEFAULT_AREA); $this->_design = $objectManager->get('Magento\\Framework\\View\\DesignInterface'); $this->_design->setDesignTheme('Vendor/test_child'); $this->_configFactory = $objectManager->create('Magento\\DesignEditor\\Model\\Editor\\Tools\\Controls\\Factory'); }
/** * Initialize dependencies */ protected function setUp() { $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); $this->_design = $objectManager->get('Magento\\Framework\\View\\DesignInterface'); $objectManager->get('Magento\\Framework\\App\\State')->setAreaCode(\Magento\Framework\View\DesignInterface::DEFAULT_AREA); $this->_design->setDesignTheme('Vendor/test'); /** @var \Magento\Framework\View\Asset\Repository $assetRepo */ $assetRepo = $objectManager->get('Magento\\Framework\\View\\Asset\\Repository'); $quickStylesPath = $assetRepo->createAsset('Magento_DesignEditor::controls/quick_styles.xml')->getSourceFile(); $this->assertFileExists($quickStylesPath); $this->_model = $objectManager->create('Magento\\DesignEditor\\Model\\Config\\Control\\QuickStyles', ['configFiles' => [file_get_contents($quickStylesPath)]]); }
/** * Initialize dependencies */ protected function setUp() { $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); /** @var \Magento\Framework\App\Filesystem\DirectoryList $directoryList */ $directoryList = $objectManager->get('Magento\\Framework\\App\\Filesystem\\DirectoryList'); $path = str_replace($directoryList->getRoot(), '', str_replace('\\', '/', __DIR__) . '/../_files/design'); $directoryList->addDirectory(\Magento\Framework\App\Filesystem::THEMES_DIR, array('path' => ltrim($path, '/'))); $this->_design = $objectManager->get('Magento\\Framework\\View\\DesignInterface'); $objectManager->get('Magento\\Framework\\App\\State')->setAreaCode(\Magento\Framework\View\DesignInterface::DEFAULT_AREA); $this->_design->setDesignTheme('vendor_test'); /** @var \Magento\Framework\View\Asset\Repository $assetRepo */ $assetRepo = $objectManager->get('Magento\\Framework\\View\\Asset\\Repository'); $quickStylesPath = $assetRepo->createAsset('Magento_DesignEditor::controls/quick_styles.xml')->getSourceFile(); $this->assertFileExists($quickStylesPath); $this->_model = $objectManager->create('Magento\\DesignEditor\\Model\\Config\\Control\\QuickStyles', array('configFiles' => array(file_get_contents($quickStylesPath)))); }
/** * Renders CMS page * * @param Action $action * @param int $pageId * @param bool $renderLayout * @return bool */ protected function _renderPage(Action $action, $pageId = null, $renderLayout = true) { if (!is_null($pageId) && $pageId !== $this->_page->getId()) { $delimiterPosition = strrpos($pageId, '|'); if ($delimiterPosition) { $pageId = substr($pageId, 0, $delimiterPosition); } $this->_page->setStoreId($this->_storeManager->getStore()->getId()); if (!$this->_page->load($pageId)) { return false; } } if (!$this->_page->getId()) { return false; } $inRange = $this->_localeDate->isScopeDateInInterval(null, $this->_page->getCustomThemeFrom(), $this->_page->getCustomThemeTo()); if ($this->_page->getCustomTheme()) { if ($inRange) { $this->_design->setDesignTheme($this->_page->getCustomTheme()); } } $this->_view->getLayout()->getUpdate()->addHandle('default')->addHandle('cms_page_view'); $this->_view->addPageLayoutHandles(array('id' => $this->_page->getIdentifier())); $this->_view->addActionLayoutHandles(); if ($this->_page->getRootTemplate()) { if ($this->_page->getCustomRootTemplate() && $this->_page->getCustomRootTemplate() != 'empty' && $inRange) { $handle = $this->_page->getCustomRootTemplate(); } else { $handle = $this->_page->getRootTemplate(); } $this->_pageLayout->applyHandle($handle); } $this->_eventManager->dispatch('cms_page_render', array('page' => $this->_page, 'controller_action' => $action)); $this->_view->loadLayoutUpdates(); if ($this->_page->getCustomLayoutUpdateXml() && $inRange) { $layoutUpdate = $this->_page->getCustomLayoutUpdateXml(); } else { $layoutUpdate = $this->_page->getLayoutUpdateXml(); } if (!empty($layoutUpdate)) { $this->_view->getLayout()->getUpdate()->addUpdate($layoutUpdate); } $this->_view->generateLayoutXml()->generateLayoutBlocks(); $contentHeadingBlock = $this->_view->getLayout()->getBlock('page_content_heading'); if ($contentHeadingBlock) { $contentHeading = $this->_escaper->escapeHtml($this->_page->getContentHeading()); $contentHeadingBlock->setContentHeading($contentHeading); } if ($this->_page->getRootTemplate()) { $this->_pageLayout->applyTemplate($this->_page->getRootTemplate()); } /* @TODO: Move catalog and checkout storage types to appropriate modules */ $messageBlock = $this->_view->getLayout()->getMessagesBlock(); $messageBlock->addStorageType($this->messageManager->getDefaultGroup()); $messageBlock->addMessages($this->messageManager->getMessages(true)); if ($renderLayout) { $this->_view->renderLayout(); } return true; }
/** * Return result blog page * * @param Action $action * @param \Magento\Framework\Model\AbstractModel $page * @return \Magento\Framework\View\Result\Page|bool */ public function prepareResultPage(Action $action, $page) { if ($page->getCustomThemeFrom() && $page->getCustomThemeTo()) { $inRange = $this->_localeDate->isScopeDateInInterval(null, $page->getCustomThemeFrom(), $page->getCustomThemeTo()); } else { $inRange = false; } if ($page->getCustomTheme()) { if ($inRange) { $this->_design->setDesignTheme($page->getCustomTheme()); } } /** @var \Magento\Framework\View\Result\Page $resultPage */ $resultPage = $this->resultPageFactory->create(); if ($inRange && $page->getCustomLayout() && $page->getCustomLayout() != 'empty') { $handle = $page->getCustomLayout(); } else { $handle = $page->getPageLayout(); } if ($handle) { $resultPage->getConfig()->setPageLayout($handle); } $fullActionName = $action->getRequest()->getFullActionName(); $resultPage->addHandle($fullActionName); $resultPage->addPageLayoutHandles(['id' => $page->getIdentifier()]); $this->_eventManager->dispatch($fullActionName . '_render', ['page' => $page, 'controller_action' => $action]); if ($inRange && $page->getCustomLayoutUpdateXml()) { $layoutUpdate = $page->getCustomLayoutUpdateXml(); } else { $layoutUpdate = $page->getLayoutUpdateXml(); } if ($layoutUpdate) { $resultPage->getLayout()->getUpdate()->addUpdate($layoutUpdate); } return $resultPage; }
/** * Return result CMS page * * @param Action $action * @param null $pageId * @return \Magento\Framework\View\Result\Page|bool */ public function prepareResultPage(Action $action, $pageId = null) { if ($pageId !== null && $pageId !== $this->_page->getId()) { $delimiterPosition = strrpos($pageId, '|'); if ($delimiterPosition) { $pageId = substr($pageId, 0, $delimiterPosition); } $this->_page->setStoreId($this->_storeManager->getStore()->getId()); if (!$this->_page->load($pageId)) { return false; } } if (!$this->_page->getId()) { return false; } $inRange = $this->_localeDate->isScopeDateInInterval(null, $this->_page->getCustomThemeFrom(), $this->_page->getCustomThemeTo()); if ($this->_page->getCustomTheme()) { if ($inRange) { $this->_design->setDesignTheme($this->_page->getCustomTheme()); } } /** @var \Magento\Framework\View\Result\Page $resultPage */ $resultPage = $this->resultPageFactory->create(); $this->setLayoutType($inRange, $resultPage); $resultPage->addHandle('cms_page_view'); $resultPage->addPageLayoutHandles(['id' => $this->_page->getIdentifier()]); $this->_eventManager->dispatch('cms_page_render', ['page' => $this->_page, 'controller_action' => $action]); if ($this->_page->getCustomLayoutUpdateXml() && $inRange) { $layoutUpdate = $this->_page->getCustomLayoutUpdateXml(); } else { $layoutUpdate = $this->_page->getLayoutUpdateXml(); } if (!empty($layoutUpdate)) { $resultPage->getLayout()->getUpdate()->addUpdate($layoutUpdate); } $contentHeadingBlock = $resultPage->getLayout()->getBlock('page_content_heading'); if ($contentHeadingBlock) { $contentHeading = $this->_escaper->escapeHtml($this->_page->getContentHeading()); $contentHeadingBlock->setContentHeading($contentHeading); } /* @TODO: Move catalog and checkout storage types to appropriate modules */ $messageBlock = $resultPage->getLayout()->getMessagesBlock(); $messageBlock->addStorageType($this->messageManager->getDefaultGroup()); $messageBlock->addMessages($this->messageManager->getMessages(true)); return $resultPage; }
/** * Manually set a theme that will be used by getParams * * Used to force the loading of an email template from a specific theme * * @param string $templateId * @param string $theme * @return $this */ public function setForcedTheme($templateId, $theme) { $area = $this->emailConfig->getTemplateArea($templateId); $this->design->setDesignTheme($theme, $area); return $this; }
/** * Apply custom design * * @param string $design * @return $this */ public function applyCustomDesign($design) { $this->_design->setDesignTheme($design); return $this; }
public function testSetDesignTheme() { $this->_model->setDesignTheme('Magento/blank', 'frontend'); $this->assertEquals('Magento/blank', $this->_model->getDesignTheme()->getThemePath()); }
/** * Apply design change from self data into specified design package instance * * @param \Magento\Framework\View\DesignInterface $packageInto * @return $this */ public function changeDesign(\Magento\Framework\View\DesignInterface $packageInto) { $design = $this->getDesign(); if ($design) { $packageInto->setDesignTheme($design); } return $this; }