| Current Path : /var/www/html/app/code/FlipsDigital/TextbookList/Controller/Adminhtml/TextbookList/ |
| Current File : /var/www/html/app/code/FlipsDigital/TextbookList/Controller/Adminhtml/TextbookList/MassDelete.php |
<?php
/**
* MassDelete.php
*
* @copyright Copyright © 2021 FlipsDigital. All rights reserved.
* @author calvin.so@flipsdigital.com
*/
namespace FlipsDigital\TextbookList\Controller\Adminhtml\TextbookList;
use Magento\Backend\App\Action;
use Magento\Backend\App\Action\Context;
use Magento\Ui\Component\MassAction\Filter;
use Magento\Framework\Controller\ResultFactory;
use FlipsDigital\TextbookList\Model\ResourceModel\TextbookList\Collection;
/**
* Class MassDelete
*/
class MassDelete extends Action
{
/**
* @var Filter
*/
protected $filter;
/** @var Collection $objectCollection */
protected $objectCollection;
/**
* @param Context $context
* @param Filter $filter
* @param Collection $objectCollection
*/
public function __construct(Context $context, Filter $filter, Collection $objectCollection)
{
$this->filter = $filter;
$this->objectCollection = $objectCollection;
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->objectCollection);
$collectionSize = $collection->getSize();
$collection->walk('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('*/*/');
}
}