forked from magento/magento2-phpstorm-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDelete.php
67 lines (59 loc) · 1.93 KB
/
Delete.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
namespace Foo\Bar\Controller\Adminhtml\Company;
use Foo\Bar\Command\Company\DeleteByIdCommand;
use Foo\Bar\Model\Data\CompanyData;
use Magento\Backend\App\Action;
use Magento\Backend\App\Action\Context;
use Magento\Framework\App\Action\HttpGetActionInterface;
use Magento\Framework\App\Action\HttpPostActionInterface;
use Magento\Framework\Controller\ResultFactory;
use Magento\Framework\Controller\ResultInterface;
use Magento\Framework\Exception\CouldNotDeleteException;
use Magento\Framework\Exception\NoSuchEntityException;
/**
* Delete Company controller.
*/
class Delete extends Action implements HttpPostActionInterface, HttpGetActionInterface
{
/**
* Authorization level of a basic admin session.
*
* @see _isAllowed()
*/
const ADMIN_RESOURCE = 'Foo_Bar::company_id';
/**
* @var DeleteByIdCommand
*/
private $deleteByIdCommand;
/**
* @param Context $context
* @param DeleteByIdCommand $deleteByIdCommand
*/
public function __construct(
Context $context,
DeleteByIdCommand $deleteByIdCommand
)
{
parent::__construct($context);
$this->deleteByIdCommand = $deleteByIdCommand;
}
/**
* Delete Company action.
*
* @return ResultInterface
*/
public function execute()
{
/** @var ResultInterface $resultRedirect */
$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
$resultRedirect->setPath('*/*/');
$entityId = (int)$this->getRequest()->getParam(CompanyData::COMPANY_ID);
try {
$this->deleteByIdCommand->execute($entityId);
$this->messageManager->addSuccessMessage(__('You have successfully deleted Company entity'));
} catch (CouldNotDeleteException | NoSuchEntityException $exception) {
$this->messageManager->addErrorMessage($exception->getMessage());
}
return $resultRedirect;
}
}