Files
2026-09-15 10:35:56 +08:00

37 lines
1.1 KiB
PHP

<?php
declare(strict_types=1);
namespace Esun\Agent\Controller\Adminhtml\Application;
use Esun\Agent\Model\ResourceModel\Application\CollectionFactory;
use Magento\Backend\App\Action;
use Magento\Framework\Controller\Result\Redirect;
use Magento\Ui\Component\MassAction\Filter;
class MassDelete extends Action
{
public const ADMIN_RESOURCE = 'Esun_Agent::applications_delete';
public function __construct(
Action\Context $context,
private readonly Filter $filter,
private readonly CollectionFactory $collectionFactory
) {
parent::__construct($context);
}
public function execute(): Redirect
{
$collection = $this->filter->getCollection($this->collectionFactory->create());
$deleted = 0;
foreach ($collection as $application) {
$application->delete();
$deleted++;
}
$this->messageManager->addSuccessMessage(
__('A total of %1 application(s) have been deleted.', $deleted)
);
return $this->resultRedirectFactory->create()->setPath('*/*/');
}
}