filter = $filter; $this->collectionFactory = $collectionFactory; parent::__construct($context); } /** * @return $this|ResponseInterface|ResultInterface * @throws LocalizedException */ public function execute() { $collection = $this->filter->getCollection($this->collectionFactory->create()); $status = (int)$this->getRequest()->getParam('status'); $topicUpdated = 0; foreach ($collection as $topic) { try { $topic->setEnabled($status) ->save(); $topicUpdated++; } catch (LocalizedException $e) { $this->messageManager->addErrorMessage($e->getMessage()); } catch (Exception $e) { $this->_getSession()->addException( $e, __('Something went wrong while updating status for %1.', $topic->getName()) ); } } if ($topicUpdated) { $this->messageManager->addSuccessMessage(__('A total of %1 record(s) have been updated.', $topicUpdated)); } /** @var Redirect $resultRedirect */ $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); return $resultRedirect->setPath('*/*/'); } }