Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AbstractMassAction.php
Go to the documentation of this file.
1 <?php
7 
14 use Magento\Customer\Model\ResourceModel\Customer\CollectionFactory;
15 
20 {
26  const ADMIN_RESOURCE = 'Magento_Customer::manage';
27 
31  protected $redirectUrl = '*/*/index';
32 
36  protected $filter;
37 
41  protected $collectionFactory;
42 
48  public function __construct(Context $context, Filter $filter, CollectionFactory $collectionFactory)
49  {
50  parent::__construct($context);
51  $this->filter = $filter;
52  $this->collectionFactory = $collectionFactory;
53  }
54 
61  public function execute()
62  {
63  try {
64  $collection = $this->filter->getCollection($this->collectionFactory->create());
65  return $this->massAction($collection);
66  } catch (\Exception $e) {
67  $this->messageManager->addError($e->getMessage());
69  $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
70  return $resultRedirect->setPath($this->redirectUrl);
71  }
72  }
73 
80  protected function getComponentRefererUrl()
81  {
82  return $this->filter->getComponentRefererUrl()?: 'customer/*/index';
83  }
84 
91  abstract protected function massAction(AbstractCollection $collection);
92 }
__construct(Context $context, Filter $filter, CollectionFactory $collectionFactory)