filter = $filter; $this->collectionFactory = $collectionFactory; parent::__construct($context); } /** * @return $this|ResponseInterface|ResultInterface * @throws LocalizedException */ public function execute() { $collection = $this->filter->getCollection($this->collectionFactory->create()); try { $count = 0; foreach ($collection as $item) { $item->delete(); $count++; } $this->messageManager->addSuccessMessage(__('Total of %1 comments has been deleted.', $count)); } catch (Exception $e) { $this->messageManager->addErrorMessage(__('Something wrong when delete Comments.')); } /** @var Redirect $resultRedirect */ $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); return $resultRedirect->setPath('*/*/'); } }