Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Edit.php
Go to the documentation of this file.
1 <?php
8 
16 class Edit extends \Magento\Backend\Block\Widget\Form\Container
17 {
23  protected $_coreRegistry = null;
24 
30  public function __construct(
31  \Magento\Backend\Block\Widget\Context $context,
32  \Magento\Framework\Registry $registry,
33  array $data = []
34  ) {
35  $this->_coreRegistry = $registry;
36  parent::__construct($context, $data);
37  }
38 
44  protected function _construct()
45  {
46  $this->_objectId = 'user_id';
47  $this->_controller = 'user';
48  $this->_blockGroup = 'Magento_User';
49 
50  parent::_construct();
51 
52  $this->buttonList->update('save', 'label', __('Save User'));
53  $this->buttonList->remove('delete');
54 
55  $objId = (int)$this->getRequest()->getParam($this->_objectId);
56 
57  if (!empty($objId)) {
58  $this->addButton(
59  'delete',
60  [
61  'label' => __('Delete User'),
62  'class' => 'delete',
63  'data_attribute' => [
64  'role' => 'delete-user'
65  ]
66  ]
67  );
68 
69  $deleteConfirmMsg = __("Are you sure you want to revoke the user's tokens?");
70  $this->addButton(
71  'invalidate',
72  [
73  'label' => __('Force Sign-In'),
74  'class' => 'invalidate-token',
75  'onclick' => "deleteConfirm('" . $this->escapeJs($this->escapeHtml($deleteConfirmMsg)) .
76  "', '" . $this->getInvalidateUrl() . "')",
77  ]
78  );
79  }
80  }
81 
92  public function getDeleteMessage()
93  {
94  return __('Are you sure you want to do this?');
95  }
96 
105  public function getDeleteUrl()
106  {
107  return $this->getUrl('adminhtml/*/delete');
108  }
109 
118  public function getObjectId()
119  {
120  return (int)$this->getRequest()->getParam($this->_objectId);
121  }
122 
126  public function getHeaderText()
127  {
128  if ($this->_coreRegistry->registry('permissions_user')->getId()) {
129  $username = $this->escapeHtml($this->_coreRegistry->registry('permissions_user')->getUsername());
130  return __("Edit User '%1'", $username);
131  } else {
132  return __('New User');
133  }
134  }
135 
141  public function getValidationUrl()
142  {
143  return $this->getUrl('adminhtml/*/validate', ['_current' => true]);
144  }
145 
151  public function getInvalidateUrl()
152  {
153  return $this->getUrl('adminhtml/*/invalidatetoken', ['_current' => true]);
154  }
155 }
__construct(\Magento\Backend\Block\Widget\Context $context, \Magento\Framework\Registry $registry, array $data=[])
Definition: Edit.php:30
__()
Definition: __.php:13
addButton($buttonId, $data, $level=0, $sortOrder=0, $region='toolbar')
Definition: Container.php:85