Exemplo n.º 1
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('tbslider/slider_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()) {
         $slider = $this->_sliderFactory->create()->load($element->getValue());
         if ($slider->getId()) {
             $chooser->setLabel($this->escapeHtml($slider->getTitle()));
         }
     }
     $element->setData('after_element_html', $chooser->toHtml());
     return $element;
 }
 /**
  * {@inheritdoc}
  */
 public function getList(SearchCriteriaInterface $searchCriteria)
 {
     $searchResults = $this->searchResultsFactory->create();
     $searchResults->setSearchCriteria($searchCriteria);
     /** @var \Stepzerosolutions\Tbslider\Model\ResourceModel\Slider\Collection $collection */
     $collection = $this->sliderFactory->create()->getCollection();
     $sliderInterfaceName = 'Stepzerosolutions\\Tbslider\\Api\\Data\\SliderInterface';
     //die( var_dump($collection) );
     //Add filters from root filter group to the collection
     /** @var FilterGroup $group */
     foreach ($searchCriteria->getFilterGroups() as $slider) {
         $this->addFilterGroupToCollection($slider, $collection);
     }
     $sortOrders = $searchCriteria->getSortOrders();
     /** @var SortOrder $sortOrder */
     if ($sortOrders) {
         foreach ($searchCriteria->getSortOrders() as $sortOrder) {
             $field = $this->translateField($sortOrder->getField());
             $collection->addOrder($field, $sortOrder->getDirection() == SortOrder::SORT_ASC ? 'ASC' : 'DESC');
         }
     } else {
         // set a default sorting order since this method is used constantly in many
         // different blocks
         $field = $this->translateField('slider_id');
         $collection->addOrder($field, 'ASC');
     }
     $collection->setCurPage($searchCriteria->getCurrentPage());
     $collection->setPageSize($searchCriteria->getPageSize());
     /** @var \Stepzerosolutions\Tbslider\Api\Data\SliderInterface[] $slider */
     $groups = [];
     /** @var \Stepzerosolutions\Tbslider\Model\Slider $slider */
     foreach ($collection as $slide) {
         /** @var \Stepzerosolutions\Tbslider\Api\Data\SliderInterface $sliderDataObject */
         $sliderDataObject = $this->sliderDataFactory->create()->setId($slide->getId())->setSliderTitle($slide->getSliderTitle());
         $data = $slide->getData();
         $slider[] = $sliderDataObject;
     }
     $searchResults->setTotalCount($collection->getSize());
     return $searchResults->setItems($slider);
 }