init
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
<?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('*/*/');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Esun\ContactPopup\Controller\Adminhtml\Submission;
|
||||
|
||||
use Magento\Backend\App\Action;
|
||||
use Magento\Backend\App\Action\Context;
|
||||
use Magento\Framework\View\Result\Page;
|
||||
use Magento\Framework\View\Result\PageFactory;
|
||||
|
||||
class Index extends Action
|
||||
{
|
||||
public const ADMIN_RESOURCE = 'Esun_ContactPopup::submissions';
|
||||
|
||||
public function __construct(Context $context, private readonly PageFactory $pageFactory)
|
||||
{
|
||||
parent::__construct($context);
|
||||
}
|
||||
|
||||
public function execute(): Page
|
||||
{
|
||||
$page = $this->pageFactory->create();
|
||||
$page->setActiveMenu('Esun_ContactPopup::submissions');
|
||||
$page->getConfig()->getTitle()->prepend(__('Contact Messages'));
|
||||
return $page;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Esun\ContactPopup\Controller\Adminhtml\Submission;
|
||||
|
||||
use Esun\ContactPopup\Model\ResourceModel\Submission\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_ContactPopup::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 $submission) {
|
||||
$submission->delete();
|
||||
$deleted++;
|
||||
}
|
||||
$this->messageManager->addSuccessMessage(__('A total of %1 message(s) have been deleted.', $deleted));
|
||||
return $this->resultRedirectFactory->create()->setPath('*/*/');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user