Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Delete.php
Go to the documentation of this file.
1 <?php
8 
10 
11 class Delete extends \Magento\User\Controller\Adminhtml\User\Role
12 {
18  public function execute()
19  {
21  $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
22  $rid = $this->getRequest()->getParam('rid', false);
24  $currentUser = $this->_userFactory->create()->setId($this->_authSession->getUser()->getId());
25 
26  if (in_array($rid, $currentUser->getRoles())) {
27  $this->messageManager->addError(__('You cannot delete self-assigned roles.'));
28  return $resultRedirect->setPath('adminhtml/*/editrole', ['rid' => $rid]);
29  }
30 
31  try {
32  $this->_initRole()->delete();
33  $this->messageManager->addSuccess(__('You deleted the role.'));
34  } catch (\Exception $e) {
35  $this->messageManager->addError(__('An error occurred while deleting this role.'));
36  }
37 
38  return $resultRedirect->setPath("*/*/");
39  }
40 }
__()
Definition: __.php:13
_initRole($requestVariable='rid')
Definition: Role.php:107