Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
MassDelete.php
Go to the documentation of this file.
1 <?php
7 
11 use Magento\Cms\Model\ResourceModel\Page\CollectionFactory;
12 
17 {
23  const ADMIN_RESOURCE = 'Magento_Cms::page_delete';
24 
28  protected $filter;
29 
33  protected $collectionFactory;
34 
40  public function __construct(Context $context, Filter $filter, CollectionFactory $collectionFactory)
41  {
42  $this->filter = $filter;
43  $this->collectionFactory = $collectionFactory;
44  parent::__construct($context);
45  }
46 
53  public function execute()
54  {
55  $collection = $this->filter->getCollection($this->collectionFactory->create());
56  $collectionSize = $collection->getSize();
57 
58  foreach ($collection as $page) {
59  $page->delete();
60  }
61 
62  $this->messageManager->addSuccessMessage(__('A total of %1 record(s) have been deleted.', $collectionSize));
63 
65  $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
66 
67  return $resultRedirect->setPath('*/*/');
68  }
69 }
__()
Definition: __.php:13
$page
Definition: pages.php:8
__construct(Context $context, Filter $filter, CollectionFactory $collectionFactory)
Definition: MassDelete.php:40