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
7 
11 
16 class Edit extends \Magento\Backend\Block\Widget\Form\Container
17 {
23  protected $_coreRegistry = null;
24 
29 
34 
40  protected $_viewHelper;
41 
52  public function __construct(
53  \Magento\Backend\Block\Widget\Context $context,
54  \Magento\Framework\Registry $registry,
57  \Magento\Customer\Helper\View $viewHelper,
58  array $data = []
59  ) {
60  $this->_coreRegistry = $registry;
61  $this->customerAccountManagement = $customerAccountManagement;
62  $this->customerRepository = $customerRepository;
63  $this->_viewHelper = $viewHelper;
64  parent::__construct($context, $data);
65  }
66 
70  protected function _construct()
71  {
72  $this->_objectId = 'id';
73  $this->_controller = 'adminhtml';
74  $this->_blockGroup = 'Magento_Customer';
75 
76  $customerId = $this->getCustomerId();
77 
78  if ($customerId && $this->_authorization->isAllowed('Magento_Sales::create')) {
79  $this->buttonList->add(
80  'order',
81  [
82  'label' => __('Create Order'),
83  'onclick' => 'setLocation(\'' . $this->getCreateOrderUrl() . '\')',
84  'class' => 'add'
85  ],
86  0
87  );
88  }
89 
90  parent::_construct();
91 
92  $this->buttonList->update('save', 'label', __('Save Customer'));
93  $this->buttonList->update('delete', 'label', __('Delete Customer'));
94 
95  if ($customerId && $this->customerAccountManagement->isReadonly($customerId)) {
96  $this->buttonList->remove('save');
97  $this->buttonList->remove('reset');
98  }
99 
100  if (!$customerId || $this->customerAccountManagement->isReadonly($customerId)) {
101  $this->buttonList->remove('delete');
102  }
103 
104  if ($customerId) {
105  $url = $this->getUrl('customer/index/resetPassword', ['customer_id' => $customerId]);
106  $this->buttonList->add(
107  'reset_password',
108  [
109  'label' => __('Reset Password'),
110  'onclick' => 'setLocation(\'' . $url . '\')',
111  'class' => 'reset reset-password'
112  ],
113  0
114  );
115  }
116 
117  if ($customerId) {
118  $url = $this->getUrl('customer/customer/invalidateToken', ['customer_id' => $customerId]);
119  $deleteConfirmMsg = __("Are you sure you want to revoke the customer's tokens?");
120  $this->buttonList->add(
121  'invalidate_token',
122  [
123  'label' => __('Force Sign-In'),
124  'onclick' => 'deleteConfirm(\'' . $this->escapeJs($this->escapeHtml($deleteConfirmMsg)) .
125  '\', \'' . $url . '\')',
126  'class' => 'invalidate-token'
127  ],
128  10
129  );
130  }
131  }
132 
138  public function getCreateOrderUrl()
139  {
140  return $this->getUrl('sales/order_create/start', ['customer_id' => $this->getCustomerId()]);
141  }
142 
148  public function getCustomerId()
149  {
150  $customerId = $this->_coreRegistry->registry(RegistryConstants::CURRENT_CUSTOMER_ID);
151  return $customerId;
152  }
153 
159  public function getHeaderText()
160  {
161  $customerId = $this->getCustomerId();
162  if ($customerId) {
163  $customerData = $this->customerRepository->getById($customerId);
164  return $this->escapeHtml($this->_viewHelper->getCustomerName($customerData));
165  } else {
166  return __('New Customer');
167  }
168  }
169 
175  public function getFormHtml()
176  {
177  $html = parent::getFormHtml();
178  $html .= $this->getLayout()->createBlock(
179  \Magento\Catalog\Block\Adminhtml\Product\Composite\Configure::class
180  )->toHtml();
181  return $html;
182  }
183 
189  public function getValidationUrl()
190  {
191  return $this->getUrl('customer/*/validate', ['_current' => true]);
192  }
193 
199  protected function _prepareLayout()
200  {
201  $customerId = $this->getCustomerId();
202  if (!$customerId || !$this->customerAccountManagement->isReadonly($customerId)) {
203  $this->buttonList->add(
204  'save_and_continue',
205  [
206  'label' => __('Save and Continue Edit'),
207  'class' => 'save',
208  'data_attribute' => [
209  'mage-init' => [
210  'button' => ['event' => 'saveAndContinueEdit', 'target' => '#edit_form'],
211  ],
212  ]
213  ],
214  10
215  );
216  }
217 
218  return parent::_prepareLayout();
219  }
220 
226  protected function _getSaveAndContinueUrl()
227  {
228  return $this->getUrl(
229  'customer/index/save',
230  ['_current' => true, 'back' => 'edit', 'tab' => '{{tab_id}}']
231  );
232  }
233 }
__()
Definition: __.php:13
__construct(\Magento\Backend\Block\Widget\Context $context, \Magento\Framework\Registry $registry, AccountManagementInterface $customerAccountManagement, CustomerRepositoryInterface $customerRepository, \Magento\Customer\Helper\View $viewHelper, array $data=[])
Definition: Edit.php:52