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'); $authorUpdated = 0; foreach ($collection as $post) { try { $post->setStatus($status) ->save(); $authorUpdated++; } catch (LocalizedException $e) { $this->messageManager->addErrorMessage($e->getMessage()); } catch (Exception $e) { $this->_getSession()->addException( $e, __('Something went wrong while updating status for %1.', $post->getName()) ); } } if ($authorUpdated) { $this->messageManager->addSuccessMessage(__('A total of %1 record(s) have been updated.', $authorUpdated)); } /** @var Redirect $resultRedirect */ $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); return $resultRedirect->setPath('*/*/'); } }