Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
All Data Structures Namespaces Files Functions Variables Pages
MassDelete.php
Go to the documentation of this file.
1 <?php
8 
12 use Magento\Cms\Model\ResourceModel\Block\CollectionFactory;
13 
18 {
24  const ADMIN_RESOURCE = 'Magento_Cms::block';
25 
29  protected $filter;
30 
34  protected $collectionFactory;
35 
41  public function __construct(Context $context, Filter $filter, CollectionFactory $collectionFactory)
42  {
43  $this->filter = $filter;
44  $this->collectionFactory = $collectionFactory;
45  parent::__construct($context);
46  }
47 
54  public function execute()
55  {
56  $collection = $this->filter->getCollection($this->collectionFactory->create());
57  $collectionSize = $collection->getSize();
58 
59  foreach ($collection as $block) {
60  $block->delete();
61  }
62 
63  $this->messageManager->addSuccessMessage(__('A total of %1 record(s) have been deleted.', $collectionSize));
64 
66  $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
67  return $resultRedirect->setPath('*/*/');
68  }
69 }
__()
Definition: __.php:13
__construct(Context $context, Filter $filter, CollectionFactory $collectionFactory)
Definition: MassDelete.php:41
$block
Definition: block.php:8