Esempio n. 1
0
 /**
  * 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();
 }
Esempio n. 2
0
 /**
  * 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;
 }
Esempio n. 3
0
 /**
  * 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;
 }
Esempio n. 4
0
 /**
  * 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;
 }
Esempio n. 5
0
 /**
  * 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);
 }