AbstractMassAction.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Sales\Controller\Adminhtml\Order;
  7. use Magento\Backend\App\Action\Context;
  8. use Magento\Framework\App\ResponseInterface;
  9. use Magento\Framework\Controller\ResultFactory;
  10. use Magento\Framework\Controller\ResultInterface;
  11. use Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection;
  12. use Magento\Ui\Component\MassAction\Filter;
  13. /**
  14. * Class AbstractMassStatus
  15. * @deprecated 101.0.0
  16. * Never extend from this action. Implement mass-action logic in the "execute" method of your controller.
  17. */
  18. abstract class AbstractMassAction extends \Magento\Backend\App\Action
  19. {
  20. /**
  21. * Authorization level of a basic admin session
  22. */
  23. const ADMIN_RESOURCE = 'Magento_Sales::actions_edit';
  24. /**
  25. * @var string
  26. */
  27. protected $redirectUrl = '*/*/';
  28. /**
  29. * @var \Magento\Ui\Component\MassAction\Filter
  30. */
  31. protected $filter;
  32. /**
  33. * @var object
  34. */
  35. protected $collectionFactory;
  36. /**
  37. * @param Context $context
  38. * @param Filter $filter
  39. */
  40. public function __construct(Context $context, Filter $filter)
  41. {
  42. parent::__construct($context);
  43. $this->filter = $filter;
  44. }
  45. /**
  46. * Execute action
  47. *
  48. * @return \Magento\Backend\Model\View\Result\Redirect
  49. * @throws \Magento\Framework\Exception\LocalizedException|\Exception
  50. */
  51. public function execute()
  52. {
  53. try {
  54. $collection = $this->filter->getCollection($this->collectionFactory->create());
  55. return $this->massAction($collection);
  56. } catch (\Exception $e) {
  57. $this->messageManager->addErrorMessage($e->getMessage());
  58. /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
  59. $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
  60. return $resultRedirect->setPath($this->redirectUrl);
  61. }
  62. }
  63. /**
  64. * Return component referrer url
  65. * TODO: Technical dept referrer url should be implement as a part of Action configuration in appropriate way
  66. *
  67. * @return null|string
  68. */
  69. protected function getComponentRefererUrl()
  70. {
  71. return $this->filter->getComponentRefererUrl() ?: 'sales/*/';
  72. }
  73. /**
  74. * Set status to collection items
  75. *
  76. * @param AbstractCollection $collection
  77. * @return ResponseInterface|ResultInterface
  78. */
  79. abstract protected function massAction(AbstractCollection $collection);
  80. }