diff --git a/vendor/magento/module-customer/Controller/Account/Edit.php b/vendor/magento/module-customer/Controller/Account/Edit.php index 2bd4862e42390..3e8a3ba3ae4d5 100644 --- a/vendor/magento/module-customer/Controller/Account/Edit.php +++ b/vendor/magento/module-customer/Controller/Account/Edit.php @@ -5,11 +5,14 @@ */ namespace Magento\Customer\Controller\Account; +use Magento\Customer\Api\CustomerMetadataInterface; use Magento\Customer\Api\CustomerRepositoryInterface; +use Magento\Customer\Model\Metadata\FormFactory; use Magento\Customer\Model\Session; use Magento\Framework\Api\DataObjectHelper; use Magento\Framework\App\Action\Context; use Magento\Framework\App\Action\HttpGetActionInterface; +use Magento\Framework\App\ObjectManager; use Magento\Framework\View\Result\PageFactory; class Edit extends \Magento\Customer\Controller\AbstractAccount implements HttpGetActionInterface @@ -34,24 +37,32 @@ class Edit extends \Magento\Customer\Controller\AbstractAccount implements HttpG */ protected $resultPageFactory; + /** + * @var FormFactory + */ + private $formFactory; + /** * @param Context $context * @param Session $customerSession * @param PageFactory $resultPageFactory * @param CustomerRepositoryInterface $customerRepository * @param DataObjectHelper $dataObjectHelper + * @param FormFactory|null $formFactory */ public function __construct( Context $context, Session $customerSession, PageFactory $resultPageFactory, CustomerRepositoryInterface $customerRepository, - DataObjectHelper $dataObjectHelper + DataObjectHelper $dataObjectHelper, + ?FormFactory $formFactory = null ) { $this->session = $customerSession; $this->resultPageFactory = $resultPageFactory; $this->customerRepository = $customerRepository; $this->dataObjectHelper = $dataObjectHelper; + $this->formFactory = $formFactory ?: ObjectManager::getInstance()->get(FormFactory::class); parent::__construct($context); } @@ -74,11 +85,19 @@ public function execute() $customerId = $this->session->getCustomerId(); $customerDataObject = $this->customerRepository->getById($customerId); if (!empty($data)) { + $customerForm = $this->formFactory->create( + CustomerMetadataInterface::ENTITY_TYPE_CUSTOMER, + EditPost::FORM_DATA_EXTRACTOR_CODE + ); + $data = array_intersect_key($data, $customerForm->getAllowedAttributes()); + $this->dataObjectHelper->populateWithArray( $customerDataObject, $data, \Magento\Customer\Api\Data\CustomerInterface::class ); + + $customerDataObject->setId($customerId); } $this->session->setCustomerData($customerDataObject);