Edit.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Customer\Block\Form;
  7. use Magento\Customer\Api\CustomerRepositoryInterface;
  8. use Magento\Customer\Model\AccountManagement;
  9. /**
  10. * Customer edit form block
  11. *
  12. * @api
  13. * @SuppressWarnings(PHPMD.DepthOfInheritance)
  14. * @since 100.0.2
  15. */
  16. class Edit extends \Magento\Customer\Block\Account\Dashboard
  17. {
  18. /**
  19. * Retrieve form data
  20. *
  21. * @return array
  22. */
  23. protected function getFormData()
  24. {
  25. $data = $this->getData('form_data');
  26. if ($data === null) {
  27. $formData = $this->customerSession->getCustomerFormData(true);
  28. $data = [];
  29. if ($formData) {
  30. $data['data'] = $formData;
  31. $data['customer_data'] = 1;
  32. }
  33. $this->setData('form_data', $data);
  34. }
  35. return $data;
  36. }
  37. /**
  38. * Restore entity data from session. Entity and form code must be defined for the form.
  39. *
  40. * @param \Magento\Customer\Model\Metadata\Form $form
  41. * @param null $scope
  42. * @return \Magento\Customer\Block\Form\Register
  43. */
  44. public function restoreSessionData(\Magento\Customer\Model\Metadata\Form $form, $scope = null)
  45. {
  46. $formData = $this->getFormData();
  47. if (isset($formData['customer_data']) && $formData['customer_data']) {
  48. $request = $form->prepareRequest($formData['data']);
  49. $data = $form->extractData($request, $scope, false);
  50. $form->restoreData($data);
  51. }
  52. return $this;
  53. }
  54. /**
  55. * Return whether the form should be opened in an expanded mode showing the change password fields
  56. *
  57. * @return bool
  58. *
  59. * @SuppressWarnings(PHPMD.BooleanGetMethodName)
  60. */
  61. public function getChangePassword()
  62. {
  63. return $this->customerSession->getChangePassword();
  64. }
  65. /**
  66. * Get minimum password length
  67. *
  68. * @return string
  69. * @since 100.1.0
  70. */
  71. public function getMinimumPasswordLength()
  72. {
  73. return $this->_scopeConfig->getValue(AccountManagement::XML_PATH_MINIMUM_PASSWORD_LENGTH);
  74. }
  75. /**
  76. * Get minimum password length
  77. *
  78. * @return string
  79. * @since 100.1.0
  80. */
  81. public function getRequiredCharacterClassesNumber()
  82. {
  83. return $this->_scopeConfig->getValue(AccountManagement::XML_PATH_REQUIRED_CHARACTER_CLASSES_NUMBER);
  84. }
  85. }