Edit.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\User\Block\User;
  7. /**
  8. * User edit page
  9. *
  10. * @api
  11. * @author Magento Core Team <core@magentocommerce.com>
  12. * @since 100.0.2
  13. */
  14. class Edit extends \Magento\Backend\Block\Widget\Form\Container
  15. {
  16. /**
  17. * Core registry
  18. *
  19. * @var \Magento\Framework\Registry
  20. */
  21. protected $_coreRegistry = null;
  22. /**
  23. * @param \Magento\Backend\Block\Widget\Context $context
  24. * @param \Magento\Framework\Registry $registry
  25. * @param array $data
  26. */
  27. public function __construct(
  28. \Magento\Backend\Block\Widget\Context $context,
  29. \Magento\Framework\Registry $registry,
  30. array $data = []
  31. ) {
  32. $this->_coreRegistry = $registry;
  33. parent::__construct($context, $data);
  34. }
  35. /**
  36. * Class constructor
  37. *
  38. * @return void
  39. */
  40. protected function _construct()
  41. {
  42. $this->_objectId = 'user_id';
  43. $this->_controller = 'user';
  44. $this->_blockGroup = 'Magento_User';
  45. parent::_construct();
  46. $this->buttonList->update('save', 'label', __('Save User'));
  47. $this->buttonList->remove('delete');
  48. $objId = (int)$this->getRequest()->getParam($this->_objectId);
  49. if (!empty($objId)) {
  50. $this->addButton(
  51. 'delete',
  52. [
  53. 'label' => __('Delete User'),
  54. 'class' => 'delete',
  55. 'data_attribute' => [
  56. 'role' => 'delete-user'
  57. ]
  58. ]
  59. );
  60. $deleteConfirmMsg = __("Are you sure you want to revoke the user's tokens?");
  61. $this->addButton(
  62. 'invalidate',
  63. [
  64. 'label' => __('Force Sign-In'),
  65. 'class' => 'invalidate-token',
  66. 'onclick' => "deleteConfirm('" . $this->escapeJs($this->escapeHtml($deleteConfirmMsg)) .
  67. "', '" . $this->getInvalidateUrl() . "')",
  68. ]
  69. );
  70. }
  71. }
  72. /**
  73. * Returns message that is displayed for admin when he deletes user from the system.
  74. * To see this message admin must do the following:
  75. * - open user's account for editing;
  76. * - type current user's password in the "Current User Identity Verification" field
  77. * - click "Delete User" at top left part of the page;
  78. *
  79. * @return \Magento\Framework\Phrase
  80. * @since 101.0.0
  81. */
  82. public function getDeleteMessage()
  83. {
  84. return __('Are you sure you want to do this?');
  85. }
  86. /**
  87. * Returns the URL that is used for user deletion.
  88. * The following Action is executed if admin navigates to returned url
  89. * Magento\User\Controller\Adminhtml\User\Delete
  90. *
  91. * @return string
  92. * @since 101.0.0
  93. */
  94. public function getDeleteUrl()
  95. {
  96. return $this->getUrl('adminhtml/*/delete');
  97. }
  98. /**
  99. * This method is used to get the ID of the user who's account the Admin is editing.
  100. * It can be used to determine the reason Admin opens the page:
  101. * to create a new user account OR to edit the previously created user account
  102. *
  103. * @return int
  104. * @since 101.0.0
  105. */
  106. public function getObjectId()
  107. {
  108. return (int)$this->getRequest()->getParam($this->_objectId);
  109. }
  110. /**
  111. * @return \Magento\Framework\Phrase
  112. */
  113. public function getHeaderText()
  114. {
  115. if ($this->_coreRegistry->registry('permissions_user')->getId()) {
  116. $username = $this->escapeHtml($this->_coreRegistry->registry('permissions_user')->getUsername());
  117. return __("Edit User '%1'", $username);
  118. } else {
  119. return __('New User');
  120. }
  121. }
  122. /**
  123. * Return validation url for edit form
  124. *
  125. * @return string
  126. */
  127. public function getValidationUrl()
  128. {
  129. return $this->getUrl('adminhtml/*/validate', ['_current' => true]);
  130. }
  131. /**
  132. * Return invalidate url for edit form
  133. *
  134. * @return string
  135. */
  136. public function getInvalidateUrl()
  137. {
  138. return $this->getUrl('adminhtml/*/invalidatetoken', ['_current' => true]);
  139. }
  140. }