Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace CustomModuleControllerAdminhtmlMessages;
- use MagentoBackendAppActionContext;
- use MagentoUiComponentMassActionFilter;
- use CustomModuleModelResourceModelMessagesCollectionFactory;
- use MagentoFrameworkControllerResultFactory;
- class MassDelete extends MagentoBackendAppAction {
- /**
- * @var Filter
- */
- protected $filter;
- /**
- * @var CollectionFactory
- */
- protected $collectionFactory;
- /**
- * @param Context $context
- * @param Filter $filter
- * @param CollectionFactory $collectionFactory
- */
- public function __construct(Context $context, Filter $filter, CollectionFactory $collectionFactory) {
- $this->filter = $filter;
- $this->collectionFactory = $collectionFactory;
- parent::__construct($context);
- }
- /**
- * Execute action
- *
- * @return MagentoBackendModelViewResultRedirect
- * @throws MagentoFrameworkExceptionLocalizedException|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 MagentoBackendModelViewResultRedirect $resultRedirect */
- $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
- return $resultRedirect->setPath('*/*/');
- }
- }
- protected $_idFieldName = 'module_id';
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement