_customerRepository = $customerRepository; $this->_extensibleDataObjectConverter = $extensibleDataObjectConverter; parent::__construct($context, $registry, $formFactory, $data); } /** * Prepare the form. * * @return $this */ protected function _prepareForm() { /** @var \Magento\Framework\Data\Form $form */ $form = $this->_formFactory->create( [ 'data' => [ 'id' => 'edit_form', 'action' => $this->getUrl('customer/*/save'), 'method' => 'post', 'enctype' => 'multipart/form-data', ], ] ); $customerId = $this->_coreRegistry->registry(RegistryConstants::CURRENT_CUSTOMER_ID); if ($customerId) { $form->addField('id', 'hidden', ['name' => 'customer_id']); $customer = $this->_customerRepository->getById($customerId); $form->setValues( $this->_extensibleDataObjectConverter->toFlatArray( $customer, [], \Magento\Customer\Api\Data\CustomerInterface::class ) )->addValues( ['customer_id' => $customerId] ); } $form->setUseContainer(true); $this->setForm($form); return parent::_prepareForm(); } }