Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
MassDisable.php
Go to the documentation of this file.
1 <?php
7 
8 use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface;
12 use Magento\Cms\Model\ResourceModel\Page\CollectionFactory;
13 
17 class MassDisable extends \Magento\Backend\App\Action implements HttpPostActionInterface
18 {
24  const ADMIN_RESOURCE = 'Magento_Cms::save';
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 
58  foreach ($collection as $item) {
59  $item->setIsActive(false);
60  $item->save();
61  }
62 
63  $this->messageManager->addSuccessMessage(
64  __('A total of %1 record(s) have been disabled.', $collection->getSize())
65  );
66 
68  $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
69  return $resultRedirect->setPath('*/*/');
70  }
71 }
__()
Definition: __.php:13
__construct(Context $context, Filter $filter, CollectionFactory $collectionFactory)
Definition: MassDisable.php:41