MassEnable.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Cms\Controller\Adminhtml\Page;
  7. use Magento\Framework\App\Action\HttpPostActionInterface;
  8. use Magento\Framework\Controller\ResultFactory;
  9. use Magento\Backend\App\Action\Context;
  10. use Magento\Ui\Component\MassAction\Filter;
  11. use Magento\Cms\Model\ResourceModel\Page\CollectionFactory;
  12. /**
  13. * Class MassEnable
  14. */
  15. class MassEnable extends \Magento\Backend\App\Action implements HttpPostActionInterface
  16. {
  17. /**
  18. * Authorization level of a basic admin session
  19. *
  20. * @see _isAllowed()
  21. */
  22. const ADMIN_RESOURCE = 'Magento_Cms::save';
  23. /**
  24. * @var Filter
  25. */
  26. protected $filter;
  27. /**
  28. * @var CollectionFactory
  29. */
  30. protected $collectionFactory;
  31. /**
  32. * @param Context $context
  33. * @param Filter $filter
  34. * @param CollectionFactory $collectionFactory
  35. */
  36. public function __construct(Context $context, Filter $filter, CollectionFactory $collectionFactory)
  37. {
  38. $this->filter = $filter;
  39. $this->collectionFactory = $collectionFactory;
  40. parent::__construct($context);
  41. }
  42. /**
  43. * Execute action
  44. *
  45. * @return \Magento\Backend\Model\View\Result\Redirect
  46. * @throws \Magento\Framework\Exception\LocalizedException|\Exception
  47. */
  48. public function execute()
  49. {
  50. $collection = $this->filter->getCollection($this->collectionFactory->create());
  51. foreach ($collection as $item) {
  52. $item->setIsActive(true);
  53. $item->save();
  54. }
  55. $this->messageManager->addSuccessMessage(
  56. __('A total of %1 record(s) have been enabled.', $collection->getSize())
  57. );
  58. /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
  59. $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
  60. return $resultRedirect->setPath('*/*/');
  61. }
  62. }