mirror of
https://github.com/bdnugget/magento2.git
synced 2026-11-08 01:37:36 +00:00
71 lines
1.9 KiB
PHP
71 lines
1.9 KiB
PHP
<?php
|
|
/**
|
|
*
|
|
* Copyright © Magento, Inc. All rights reserved.
|
|
* See COPYING.txt for license details.
|
|
*/
|
|
namespace Magento\Cms\Controller\Adminhtml\Block;
|
|
|
|
use Magento\Framework\App\Action\HttpPostActionInterface;
|
|
use Magento\Framework\Controller\ResultFactory;
|
|
use Magento\Backend\App\Action\Context;
|
|
use Magento\Ui\Component\MassAction\Filter;
|
|
use Magento\Cms\Model\ResourceModel\Block\CollectionFactory;
|
|
|
|
/**
|
|
* Class MassDelete
|
|
*/
|
|
class MassDelete extends \Magento\Backend\App\Action implements HttpPostActionInterface
|
|
{
|
|
/**
|
|
* Authorization level of a basic admin session
|
|
*
|
|
* @see _isAllowed()
|
|
*/
|
|
const ADMIN_RESOURCE = 'Magento_Cms::block';
|
|
|
|
/**
|
|
* @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 \Magento\Backend\Model\View\Result\Redirect
|
|
* @throws \Magento\Framework\Exception\LocalizedException|\Exception
|
|
*/
|
|
public function execute()
|
|
{
|
|
$collection = $this->filter->getCollection($this->collectionFactory->create());
|
|
$collectionSize = $collection->getSize();
|
|
|
|
foreach ($collection as $block) {
|
|
$block->delete();
|
|
}
|
|
|
|
$this->messageManager->addSuccessMessage(__('A total of %1 record(s) have been deleted.', $collectionSize));
|
|
|
|
/** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
|
|
$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
|
|
return $resultRedirect->setPath('*/*/');
|
|
}
|
|
}
|