Exemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function run()
 {
     $this->logger->log('Installing Widgets:');
     $pageGroupConfig = ['pages' => ['block' => '', 'for' => 'all', 'layout_handle' => 'default', 'template' => 'widget/static_block/default.phtml', 'page_id' => ''], 'all_pages' => ['block' => '', 'for' => 'all', 'layout_handle' => 'default', 'template' => 'widget/static_block/default.phtml', 'page_id' => ''], 'anchor_categories' => ['entities' => '', 'block' => '', 'for' => 'all', 'is_anchor_only' => 0, 'layout_handle' => 'catalog_category_view_type_layered', 'template' => 'widget/static_block/default.phtml', 'page_id' => '']];
     foreach ($this->fixtures as $file) {
         $fileName = $this->fixtureHelper->getPath($file);
         $csvReader = $this->csvReaderFactory->create(['fileName' => $fileName, 'mode' => 'r']);
         foreach ($csvReader as $row) {
             $block = $this->cmsBlockFactory->create()->load($row['block_identifier'], 'identifier');
             if (!$block) {
                 continue;
             }
             $widgetInstance = $this->widgetFactory->create();
             $code = $row['type_code'];
             $themeId = $this->themeCollectionFactory->create()->getThemeByFullPath($row['theme_path'])->getId();
             $type = $widgetInstance->getWidgetReference('code', $code, 'type');
             $pageGroup = [];
             $group = $row['page_group'];
             $pageGroup['page_group'] = $group;
             $pageGroup[$group] = array_merge($pageGroupConfig[$group], unserialize($row['group_data']));
             if (!empty($pageGroup[$group]['entities'])) {
                 $pageGroup[$group]['entities'] = $this->getCategoryByUrlKey($pageGroup[$group]['entities'])->getId();
             }
             $widgetInstance->setType($type)->setCode($code)->setThemeId($themeId);
             $widgetInstance->setTitle($row['title'])->setStoreIds([\Magento\Store\Model\Store::DEFAULT_STORE_ID])->setWidgetParameters(['block_id' => $block->getId()])->setPageGroups([$pageGroup]);
             $widgetInstance->save();
             $this->logger->logInline('.');
         }
     }
 }
Exemplo n.º 2
0
 /**
  * @param array $data
  * @return \Magento\Cms\Model\Block
  */
 protected function saveCmsBlock($data)
 {
     $cmsBlock = $this->blockFactory->create();
     $cmsBlock->getResource()->load($cmsBlock, $data['identifier']);
     if (!$cmsBlock->getData()) {
         $cmsBlock->setData($data);
     } else {
         $cmsBlock->addData($data);
     }
     $cmsBlock->setStores([\Magento\Store\Model\Store::DEFAULT_STORE_ID]);
     $cmsBlock->setIsActive(1);
     $cmsBlock->save();
     return $cmsBlock;
 }
Exemplo n.º 3
0
 /**
  * Prepare chooser element HTML
  *
  * @param \Magento\Framework\Data\Form\Element\AbstractElement $element Form Element
  * @return \Magento\Framework\Data\Form\Element\AbstractElement
  */
 public function prepareElementHtml(\Magento\Framework\Data\Form\Element\AbstractElement $element)
 {
     $uniqId = $this->mathRandom->getUniqueHash($element->getId());
     $sourceUrl = $this->getUrl('cms/block_widget/chooser', ['uniq_id' => $uniqId]);
     $chooser = $this->getLayout()->createBlock('Magento\\Widget\\Block\\Adminhtml\\Widget\\Chooser')->setElement($element)->setConfig($this->getConfig())->setFieldsetId($this->getFieldsetId())->setSourceUrl($sourceUrl)->setUniqId($uniqId);
     if ($element->getValue()) {
         $block = $this->_blockFactory->create()->load($element->getValue());
         if ($block->getId()) {
             $chooser->setLabel($this->escapeHtml($block->getTitle()));
         }
     }
     $element->setData('after_element_html', $chooser->toHtml());
     return $element;
 }
Exemplo n.º 4
0
 /**
  * Prepare Content HTML
  *
  * @return string
  */
 protected function _toHtml()
 {
     $blockId = $this->getBlockId();
     $html = '';
     if ($blockId) {
         $storeId = $this->_storeManager->getStore()->getId();
         /** @var \Magento\Cms\Model\Block $block */
         $block = $this->_blockFactory->create();
         $block->setStoreId($storeId)->load($blockId);
         if ($block->isActive()) {
             $html = $this->_filterProvider->getBlockFilter()->setStoreId($storeId)->filter($block->getContent());
         }
     }
     return $html;
 }
Exemplo n.º 5
0
 /**
  * @covers \Magento\Cms\Block\Adminhtml\Block\Widget\Chooser::prepareElementHtml
  * @param string $elementValue
  * @param integer|null $modelBlockId
  *
  * @dataProvider prepareElementHtmlDataProvider
  */
 public function testPrepareElementHtml($elementValue, $modelBlockId)
 {
     $elementId = 1;
     $uniqId = '126hj4h3j73hk7b347jhkl37gb34';
     $sourceUrl = 'cms/block_widget/chooser/126hj4h3j73hk7b347jhkl37gb34';
     $config = ['key1' => 'value1'];
     $fieldsetId = 2;
     $html = 'some html';
     $title = 'some title';
     $this->this->setConfig($config);
     $this->this->setFieldsetId($fieldsetId);
     $this->elementMock->expects($this->atLeastOnce())->method('getId')->willReturn($elementId);
     $this->mathRandomMock->expects($this->atLeastOnce())->method('getUniqueHash')->with($elementId)->willReturn($uniqId);
     $this->urlBuilderMock->expects($this->atLeastOnce())->method('getUrl')->with('cms/block_widget/chooser', ['uniq_id' => $uniqId])->willReturn($sourceUrl);
     $this->layoutMock->expects($this->atLeastOnce())->method('createBlock')->with('Magento\\Widget\\Block\\Adminhtml\\Widget\\Chooser')->willReturn($this->chooserMock);
     $this->chooserMock->expects($this->atLeastOnce())->method('setElement')->with($this->elementMock)->willReturnSelf();
     $this->chooserMock->expects($this->atLeastOnce())->method('setConfig')->with($config)->willReturnSelf();
     $this->chooserMock->expects($this->atLeastOnce())->method('setFieldsetId')->with($fieldsetId)->willReturnSelf();
     $this->chooserMock->expects($this->atLeastOnce())->method('setSourceUrl')->with($sourceUrl)->willReturnSelf();
     $this->chooserMock->expects($this->atLeastOnce())->method('setUniqId')->with($uniqId)->willReturnSelf();
     $this->elementMock->expects($this->atLeastOnce())->method('getValue')->willReturn($elementValue);
     $this->blockFactoryMock->expects($this->any())->method('create')->willReturn($this->modelBlockMock);
     $this->modelBlockMock->expects($this->any())->method('load')->with($elementValue)->willReturnSelf();
     $this->modelBlockMock->expects($this->any())->method('getId')->willReturn($modelBlockId);
     $this->modelBlockMock->expects($this->any())->method('getTitle')->willReturn($title);
     $this->chooserMock->expects($this->any())->method('setLabel')->with($title)->willReturnSelf();
     $this->chooserMock->expects($this->atLeastOnce())->method('toHtml')->willReturn($html);
     $this->elementMock->expects($this->atLeastOnce())->method('setData')->with('after_element_html', $html)->willReturnSelf();
     $this->assertEquals($this->elementMock, $this->this->prepareElementHtml($this->elementMock));
 }
 /**
  * {@inheritdoc}
  */
 public function run()
 {
     $this->logger->log('Installing CMS blocks:');
     if (!$this->deployHelper->isMediaPresent()) {
         $this->logger->log('Sample Data Media was not installed. Skipping CMS blocks installation');
         return;
     }
     foreach ($this->fixtures as $file) {
         /** @var \Magento\SampleData\Helper\Csv\Reader */
         $fileName = $this->fixtureHelper->getPath($file);
         $csvReader = $this->csvReaderFactory->create(['fileName' => $fileName, 'mode' => 'r']);
         foreach ($csvReader as $row) {
             $data = $this->converter->convertRow($row);
             $data = $data['block'];
             /** @var \Magento\Cms\Model\Block $cmsBlock */
             $cmsBlock = $this->blockFactory->create();
             $cmsBlock->getResource()->load($cmsBlock, $data['identifier']);
             if ($cmsBlock->getId()) {
                 continue;
             }
             $cmsBlock->addData($data);
             $cmsBlock->setStores([\Magento\Store\Model\Store::DEFAULT_STORE_ID]);
             $cmsBlock->setIsActive(1);
             $cmsBlock->save();
             $cmsBlock->unsetData();
             $this->logger->logInline('.');
         }
     }
 }
Exemplo n.º 7
0
 /**
  * Load Block data by given Block Identity
  *
  * @param string $blockId
  * @return Block
  * @throws \Magento\Framework\Exception\NoSuchEntityException
  */
 public function getById($blockId)
 {
     $block = $this->blockFactory->create();
     $this->resource->load($block, $blockId);
     if (!$block->getId()) {
         throw new NoSuchEntityException(__('CMS Block with id "%1" does not exist.', $blockId));
     }
     return $block;
 }
    /**
     * {@inheritdoc}
     * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
     */
    public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
    {
        /**
         * cms page sample
         */
        $pageContent = <<<EOD
test
EOD;
        $cmsPage = ['title' => 'test', 'content_heading' => 'test', 'page_layout' => '1column', 'identifier' => 'test-cms-page', 'content' => $pageContent, 'is_active' => 1, 'stores' => [0], 'sort_order' => 0];
        $this->createPage()->setData($cmsPage)->save();
        /**
         * cms block sample
         */
        $cmsBlock = ['title' => 'test cms block', 'identifier' => 'test_cms_block', 'content' => 'cms block sample', 'is_active' => 1, 'stores' => 0];
        /** @var \Magento\Cms\Model\Block $block */
        $block = $this->blockFactory->create();
        $block->setData($cmsBlock)->save();
    }
Exemplo n.º 9
0
 /**
  * Prepare block text and determine whether block output enabled or not
  * Prevent blocks recursion if needed
  *
  * @return $this
  */
 protected function _beforeToHtml()
 {
     parent::_beforeToHtml();
     $blockId = $this->getData('block_id');
     $blockHash = get_class($this) . $blockId;
     if (isset(self::$_widgetUsageMap[$blockHash])) {
         return $this;
     }
     self::$_widgetUsageMap[$blockHash] = true;
     if ($blockId) {
         $storeId = $this->_storeManager->getStore()->getId();
         /** @var \Magento\Cms\Model\Block $block */
         $block = $this->_blockFactory->create();
         $block->setStoreId($storeId)->load($blockId);
         if ($block->isActive()) {
             $this->setText($this->_filterProvider->getBlockFilter()->setStoreId($storeId)->filter($block->getContent()));
         }
     }
     unset(self::$_widgetUsageMap[$blockHash]);
     return $this;
 }
Exemplo n.º 10
0
 /**
  * {@inheritdoc}
  */
 public function install(array $fixtures)
 {
     $pageGroupConfig = ['pages' => ['block' => '', 'for' => 'all', 'layout_handle' => 'default', 'template' => 'widget/static_block/default.phtml', 'page_id' => ''], 'all_pages' => ['block' => '', 'for' => 'all', 'layout_handle' => 'default', 'template' => 'widget/static_block/default.phtml', 'page_id' => ''], 'anchor_categories' => ['entities' => '', 'block' => '', 'for' => 'all', 'is_anchor_only' => 0, 'layout_handle' => 'catalog_category_view_type_layered', 'template' => 'widget/static_block/default.phtml', 'page_id' => '']];
     foreach ($fixtures as $fileName) {
         $fileName = $this->fixtureManager->getFixture($fileName);
         if (!file_exists($fileName)) {
             continue;
         }
         $rows = $this->csvReader->getData($fileName);
         $header = array_shift($rows);
         foreach ($rows as $row) {
             $data = [];
             foreach ($row as $key => $value) {
                 $data[$header[$key]] = $value;
             }
             $row = $data;
             /** @var \Magento\Widget\Model\ResourceModel\Widget\Instance\Collection $instanceCollection */
             $instanceCollection = $this->appCollectionFactory->create();
             $instanceCollection->addFilter('title', $row['title']);
             if ($instanceCollection->count() > 0) {
                 continue;
             }
             /** @var \Magento\Cms\Model\Block $block */
             $block = $this->cmsBlockFactory->create()->load($row['block_identifier'], 'identifier');
             if (!$block) {
                 continue;
             }
             $widgetInstance = $this->widgetFactory->create();
             $code = $row['type_code'];
             $themeId = $this->themeCollectionFactory->create()->getThemeByFullPath($row['theme_path'])->getId();
             $type = $widgetInstance->getWidgetReference('code', $code, 'type');
             $pageGroup = [];
             $group = $row['page_group'];
             $pageGroup['page_group'] = $group;
             $pageGroup[$group] = array_merge($pageGroupConfig[$group], unserialize($row['group_data']));
             if (!empty($pageGroup[$group]['entities'])) {
                 $pageGroup[$group]['entities'] = $this->getCategoryByUrlKey($pageGroup[$group]['entities'])->getId();
             }
             $widgetInstance->setType($type)->setCode($code)->setThemeId($themeId);
             $widgetInstance->setTitle($row['title'])->setStoreIds([\Magento\Store\Model\Store::DEFAULT_STORE_ID])->setWidgetParameters(['block_id' => $block->getId()])->setPageGroups([$pageGroup]);
             $widgetInstance->save();
         }
     }
 }
Exemplo n.º 11
0
 /**
  * Create block
  *
  * @return \Magento\Cms\Model\Block
  */
 public function createBlock()
 {
     return $this->_blockFactory->create();
 }