/**
  * 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());
     $collectionSize = $collection->getSize();
     foreach ($collection as $item) {
         $item->delete();
     }
     $this->messageManager->addSuccess(__('A total of %1 record(s) have been deleted.', $collectionSize));
     /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
     $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
     return $resultRedirect->setPath('*/*/');
 }
예제 #2
0
 /**
  * @return \Ashsmith\Blog\Model\ResourceModel\Post\Collection
  */
 public function getPosts()
 {
     // Check if posts has already been defined
     // makes our block nice and re-usable! We could
     // pass the 'posts' data to this block, with a collection
     // that has been filtered differently!
     if (!$this->hasData('posts')) {
         $posts = $this->_postCollectionFactory->create()->addFilter('is_active', 1)->addOrder(PostInterface::CREATION_TIME, PostCollection::SORT_ORDER_DESC);
         $this->setData('posts', $posts);
     }
     return $this->getData('posts');
 }