Example #1
0
 /**
  * Return all block options
  *
  * @return array
  */
 public function getAllOptions()
 {
     if (!$this->_options) {
         $this->_options = $this->_blockCollectionFactory->create()->load()->toOptionArray();
         array_unshift($this->_options, ['value' => '', 'label' => __('Please select a static block.')]);
     }
     return $this->_options;
 }
Example #2
0
 /**
  * Execute action
  *
  * @return \Magento\Backend\Model\View\Result\Redirect
  * @throws \Magento\Framework\Exception\LocalizedException|\Exception
  */
 public function execute()
 {
     $collection = $this->filter->getCollection($this->collectionFactory->create());
     $collectionSize = $collection->getSize();
     foreach ($collection as $block) {
         $block->delete();
     }
     $this->messageManager->addSuccess(__('A total of %1 record(s) have been deleted.', $collectionSize));
     /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
     $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
     return $resultRedirect->setPath('*/*/');
 }
Example #3
0
 public function testMassDeleteAction()
 {
     $deletedBlocksCount = 2;
     $collection = [$this->getBlockMock(), $this->getBlockMock()];
     $this->collectionFactoryMock->expects($this->once())->method('create')->willReturn($this->blockCollectionMock);
     $this->filterMock->expects($this->once())->method('getCollection')->with($this->blockCollectionMock)->willReturn($this->blockCollectionMock);
     $this->blockCollectionMock->expects($this->once())->method('getSize')->willReturn($deletedBlocksCount);
     $this->blockCollectionMock->expects($this->once())->method('getIterator')->willReturn(new \ArrayIterator($collection));
     $this->messageManagerMock->expects($this->once())->method('addSuccess')->with(__('A total of %1 record(s) have been deleted.', $deletedBlocksCount));
     $this->messageManagerMock->expects($this->never())->method('addError');
     $this->resultRedirectMock->expects($this->once())->method('setPath')->with('*/*/')->willReturnSelf();
     $this->assertSame($this->resultRedirectMock, $this->massDeleteController->executeInternal());
 }
 /**
  * Load Block data collection by given search criteria
  *
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  * @param \Magento\Framework\Api\SearchCriteriaInterface $criteria
  * @return \Magento\Cms\Model\ResourceModel\Block\Collection
  */
 public function getList(\Magento\Framework\Api\SearchCriteriaInterface $criteria)
 {
     $searchResults = $this->searchResultsFactory->create();
     $searchResults->setSearchCriteria($criteria);
     $collection = $this->blockCollectionFactory->create();
     foreach ($criteria->getFilterGroups() as $filterGroup) {
         foreach ($filterGroup->getFilters() as $filter) {
             if ($filter->getField() === 'store_id') {
                 $collection->addStoreFilter($filter->getValue(), false);
                 continue;
             }
             $condition = $filter->getConditionType() ?: 'eq';
             $collection->addFieldToFilter($filter->getField(), [$condition => $filter->getValue()]);
         }
     }
     $searchResults->setTotalCount($collection->getSize());
     $sortOrders = $criteria->getSortOrders();
     if ($sortOrders) {
         foreach ($sortOrders as $sortOrder) {
             $collection->addOrder($sortOrder->getField(), $sortOrder->getDirection() == SortOrder::SORT_ASC ? 'ASC' : 'DESC');
         }
     }
     $collection->setCurPage($criteria->getCurrentPage());
     $collection->setPageSize($criteria->getPageSize());
     $blocks = [];
     /** @var Block $blockModel */
     foreach ($collection as $blockModel) {
         $blockData = $this->dataBlockFactory->create();
         $this->dataObjectHelper->populateWithArray($blockData, $blockModel->getData(), 'Magento\\Cms\\Api\\Data\\BlockInterface');
         $blocks[] = $this->dataObjectProcessor->buildOutputDataArray($blockData, 'Magento\\Cms\\Api\\Data\\BlockInterface');
     }
     $searchResults->setItems($blocks);
     return $searchResults;
 }
Example #5
0
 /**
  * @return $this
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 protected function _prepareForm()
 {
     $model = $this->_coreRegistry->registry('slider');
     $this->blockOptions = $this->blockColFactory->create();
     $this->blockOptions = $this->blockOptions->toOptionArray();
     $isElementDisabled = true;
     $form = $this->_formFactory->create();
     /*
      * declare dependence
      */
     // dependence block
     $dependenceBlock = $this->getLayout()->createBlock('Magento\\Backend\\Block\\Widget\\Form\\Element\\Dependence');
     $fieldset = $form->addFieldset('base_fieldset', ['legend' => __('Slider Information')]);
     if ($model->getId()) {
         $fieldset->addField('slider_id', 'hidden', ['name' => 'slider_id']);
     }
     $fieldset->addField('title', 'text', ['name' => 'title', 'label' => __('Slider Title'), 'title' => __('Slider Title'), 'required' => true, 'class' => 'required-entry']);
     $fieldset->addField('slider_status', 'select', ['label' => __('Slider Status'), 'title' => __('Slider Status'), 'name' => 'slider_status', 'options' => ['1' => __('Enabled'), '0' => __('Disabled')]]);
     if (!$this->_storeManager->isSingleStoreMode()) {
         $field = $fieldset->addField('store_id', 'multiselect', ['name' => 'stores[]', 'label' => __('Store View'), 'title' => __('Store View'), 'required' => true, 'values' => $this->_systemStore->getStoreValuesForForm(false, true)]);
         $renderer = $this->getLayout()->createBlock('Magento\\Backend\\Block\\Store\\Switcher\\Form\\Renderer\\Fieldset\\Element');
         $field->setRenderer($renderer);
     } else {
         $fieldset->addField('store_id', 'hidden', ['name' => 'stores[]', 'value' => $this->_storeManager->getStore(true)->getId()]);
         $model->setStoreId($this->_storeManager->getStore(true)->getId());
     }
     $fieldset->addField('banner_number', 'text', ['name' => 'banner_number', 'label' => __('Number of banners to show'), 'title' => __('Number of banners to show'), 'required' => true]);
     $fieldset->addField('loop', 'select', ['label' => __('Intinite rotation'), 'name' => 'loop', 'options' => $this->getYesNo()]);
     $fieldset->addField('auto_width', 'select', ['label' => __('Auto Width'), 'name' => 'auto_width', 'options' => $this->getYesNo()]);
     $fieldset->addField('start_position', 'text', ['name' => 'start_position', 'label' => __('Banner number Slider should start from'), 'title' => __('Banner number Slider should start from'), 'required' => true]);
     $fieldset->addField('nav', 'select', ['label' => __('Enable Navigation'), 'name' => 'nav', 'options' => $this->getYesNo()]);
     $fieldset->addField('dots', 'select', ['label' => __('Enable Dots'), 'name' => 'dots', 'options' => $this->getYesNo()]);
     $fieldset->addField('auto_play', 'select', ['label' => __('Enable Autoplay'), 'name' => 'auto_play', 'options' => $this->getYesNo()]);
     $fieldset->addField('autoplay_timeout', 'text', ['name' => 'autoplay_timeout', 'label' => __('Please enter autoplay timeout time'), 'title' => __('Please enter autoplay timeout time'), 'required' => true]);
     $fieldset->addField('autoplay_speed', 'text', ['name' => 'autoplay_speed', 'label' => __('Please enter autoplay speed time'), 'title' => __('Please enter autoplay speed time'), 'required' => true]);
     $fieldset->addField('animate_in', 'select', ['label' => __('Please select Start Animation'), 'name' => 'animate_in', 'values' => [['value' => 'fadeIn', 'label' => __('FadeIn')], ['value' => 'slideInLeft', 'label' => __('SlideInLeft')]]]);
     $fieldset->addField('animate_out', 'select', ['label' => __('Please select End Animation'), 'name' => 'animate_out', 'values' => [['value' => 'fadeOut', 'label' => __('FadeOut')], ['value' => 'slideOutRight', 'label' => __('SlideOutRight')]]]);
     $include_block = $fieldset->addField('include_block', 'select', ['label' => __('Include Static Blocks'), 'title' => __('Slider Type'), 'name' => 'include_block', 'options' => $this->getYesNo(), 'disabled' => false]);
     $first_block = $fieldset->addField('first_block', 'select', ['name' => 'first_block', 'label' => __('CMS Block 1'), 'title' => __('CMS Block 1'), 'values' => $this->blockOptions]);
     $second_block = $fieldset->addField('second_block', 'select', ['name' => 'second_block', 'label' => __('CMS Block 2'), 'title' => __('CMS Block 2'), 'values' => $this->blockOptions]);
     $form->setHtmlIdPrefix($this->_slider->getFormFieldHtmlIdPrefix());
     $form->setValues($model->getData());
     $this->setForm($form);
     $this->setChild('form_after', $this->getLayout()->createBlock('Magento\\Backend\\Block\\Widget\\Form\\Element\\Dependence')->addFieldMap($include_block->getHtmlId(), $include_block->getName())->addFieldMap($first_block->getHtmlId(), $first_block->getName())->addFieldMap($second_block->getHtmlId(), $second_block->getName())->addFieldDependence($first_block->getName(), $include_block->getName(), '1')->addFieldDependence($second_block->getName(), $include_block->getName(), '1'));
     return parent::_prepareForm();
 }
Example #6
0
 /**
  * Constructor
  *
  * @param string $name
  * @param string $primaryFieldName
  * @param string $requestFieldName
  * @param CollectionFactory $blockCollectionFactory
  * @param FilterPool $filterPool
  * @param array $meta
  * @param array $data
  */
 public function __construct($name, $primaryFieldName, $requestFieldName, CollectionFactory $blockCollectionFactory, FilterPool $filterPool, array $meta = [], array $data = [])
 {
     parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data);
     $this->collection = $blockCollectionFactory->create();
     $this->filterPool = $filterPool;
 }
Example #7
0
 /**
  * Constructor
  *
  * @param string $name
  * @param string $primaryFieldName
  * @param string $requestFieldName
  * @param CollectionFactory $blockCollectionFactory
  * @param DataPersistorInterface $dataPersistor
  * @param array $meta
  * @param array $data
  */
 public function __construct($name, $primaryFieldName, $requestFieldName, CollectionFactory $blockCollectionFactory, DataPersistorInterface $dataPersistor, array $meta = [], array $data = [])
 {
     $this->collection = $blockCollectionFactory->create();
     $this->dataPersistor = $dataPersistor;
     parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data);
 }
Example #8
0
 /**
  * Prepare Cms static blocks collection
  *
  * @return \Magento\Backend\Block\Widget\Grid\Extended
  */
 protected function _prepareCollection()
 {
     $this->setCollection($this->_collectionFactory->create());
     return parent::_prepareCollection();
 }
Example #9
0
 /**
  * getCmsBlockCollection
  *
  * @return Collection
  */
 protected function getCmsBlockCollection()
 {
     return $this->cmsBlockCollectionFactory->create();
 }