/** * 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()); foreach ($collection as $item) { $item->setIsActive(true); $item->save(); } $this->messageManager->addSuccess(__('A total of %1 record(s) have been enabled.', $collection->getSize())); /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); return $resultRedirect->setPath('*/*/'); }
/** * @return \Fc\Faqs\Model\ResourceModel\Faq\Collection */ public function getFaqs() { // Check if faqs has already been defined // makes our block nice and re-usable! We could // pass the 'faqs' data to this block, with a collection // that has been filtered differently! /** * @todo check sort order is doing as it should * May need to be FaqInterface::SORT_ORDER_DESC */ if (!$this->hasData('faqs')) { $faqs = $this->_faqCollectionFactory->create()->addFilter('is_active', 1)->addOrder(FaqInterface::SORT_ORDER, FaqCollection::SORT_ORDER_ASC); $this->setData('faqs', $faqs); } return $this->getData('faqs'); }