Advertisement
Guest User

Untitled

a guest
Aug 28th, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. namespace CustomModuleControllerAdminhtmlMessages;
  2. use MagentoBackendAppActionContext;
  3. use MagentoUiComponentMassActionFilter;
  4. use CustomModuleModelResourceModelMessagesCollectionFactory;
  5. use MagentoFrameworkControllerResultFactory;
  6.  
  7.  
  8. class MassDelete extends MagentoBackendAppAction {
  9.  
  10. /**
  11. * @var Filter
  12. */
  13. protected $filter;
  14.  
  15. /**
  16. * @var CollectionFactory
  17. */
  18. protected $collectionFactory;
  19.  
  20. /**
  21. * @param Context $context
  22. * @param Filter $filter
  23. * @param CollectionFactory $collectionFactory
  24. */
  25. public function __construct(Context $context, Filter $filter, CollectionFactory $collectionFactory) {
  26. $this->filter = $filter;
  27. $this->collectionFactory = $collectionFactory;
  28. parent::__construct($context);
  29. }
  30.  
  31. /**
  32. * Execute action
  33. *
  34. * @return MagentoBackendModelViewResultRedirect
  35. * @throws MagentoFrameworkExceptionLocalizedException|Exception
  36. */
  37. public function execute() {
  38.  
  39. $collection = $this->filter->getCollection($this->collectionFactory->create());
  40. $collectionSize = $collection->getSize();
  41.  
  42. foreach ($collection as $item) {
  43. $item->delete();
  44. }
  45.  
  46. $this->messageManager->addSuccess(__('A total of %1 record(s) have been deleted.', $collectionSize));
  47.  
  48. /** @var MagentoBackendModelViewResultRedirect $resultRedirect */
  49. $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
  50. return $resultRedirect->setPath('*/*/');
  51. }
  52. }
  53.  
  54. protected $_idFieldName = 'module_id';
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement