Files
esun3d/app/code/Esun/ContactPopup/Controller/Adminhtml/Submission/Delete.php
T
2026-09-15 10:35:56 +08:00

34 lines
1.1 KiB
PHP

<?php
declare(strict_types=1);
namespace Esun\ContactPopup\Controller\Adminhtml\Submission;
use Esun\ContactPopup\Model\SubmissionFactory;
use Magento\Backend\App\Action;
use Magento\Framework\Controller\Result\Redirect;
class Delete extends Action
{
public const ADMIN_RESOURCE = 'Esun_ContactPopup::delete';
public function __construct(Action\Context $context, private readonly SubmissionFactory $submissionFactory)
{
parent::__construct($context);
}
public function execute(): Redirect
{
try {
$submission = $this->submissionFactory->create()->load((int)$this->getRequest()->getParam('entity_id'));
if (!$submission->getId()) {
throw new \RuntimeException('Submission not found.');
}
$submission->delete();
$this->messageManager->addSuccessMessage(__('The contact message has been deleted.'));
} catch (\Throwable $exception) {
$this->messageManager->addErrorMessage(__('The contact message could not be deleted.'));
}
return $this->resultRedirectFactory->create()->setPath('*/*/');
}
}