Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Attributes
CustomerExtractor Class Reference

Public Member Functions

 __construct (\Magento\Customer\Model\Metadata\FormFactory $formFactory, \Magento\Customer\Api\Data\CustomerInterfaceFactory $customerFactory, \Magento\Store\Model\StoreManagerInterface $storeManager, GroupManagementInterface $customerGroupManagement, \Magento\Framework\Api\DataObjectHelper $dataObjectHelper)
 
 extract ( $formCode, RequestInterface $request, array $attributeValues=[])
 

Protected Attributes

 $formFactory
 
 $customerFactory
 
 $storeManager
 
 $customerGroupManagement
 
 $dataObjectHelper
 

Detailed Description

Definition at line 14 of file CustomerExtractor.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( \Magento\Customer\Model\Metadata\FormFactory  $formFactory,
\Magento\Customer\Api\Data\CustomerInterfaceFactory  $customerFactory,
\Magento\Store\Model\StoreManagerInterface  $storeManager,
GroupManagementInterface  $customerGroupManagement,
\Magento\Framework\Api\DataObjectHelper  $dataObjectHelper 
)
Parameters
Metadata\FormFactory$formFactory
\Magento\Customer\Api\Data\CustomerInterfaceFactory$customerFactory
\Magento\Store\Model\StoreManagerInterface$storeManager
GroupManagementInterface$customerGroupManagement
\Magento\Framework\Api\DataObjectHelper$dataObjectHelper

Definition at line 48 of file CustomerExtractor.php.

Member Function Documentation

◆ extract()

extract (   $formCode,
RequestInterface  $request,
array  $attributeValues = [] 
)
Parameters
string$formCode
RequestInterface$request
array$attributeValues
Returns
CustomerInterface

Definition at line 68 of file CustomerExtractor.php.

72  {
73  $customerForm = $this->formFactory->create(
75  $formCode,
77  );
78 
79  $customerData = $customerForm->extractData($request);
80  $customerData = $customerForm->compactData($customerData);
81 
82  $allowedAttributes = $customerForm->getAllowedAttributes();
83  $isGroupIdEmpty = isset($allowedAttributes['group_id']);
84 
85  $customerDataObject = $this->customerFactory->create();
86  $this->dataObjectHelper->populateWithArray(
87  $customerDataObject,
89  \Magento\Customer\Api\Data\CustomerInterface::class
90  );
91  $store = $this->storeManager->getStore();
92  if ($isGroupIdEmpty) {
93  $customerDataObject->setGroupId(
94  $this->customerGroupManagement->getDefaultGroup($store->getId())->getId()
95  );
96  }
97 
98  $customerDataObject->setWebsiteId($store->getWebsiteId());
99  $customerDataObject->setStoreId($store->getId());
100 
101  return $customerDataObject;
102  }
$customerData

Field Documentation

◆ $customerFactory

$customerFactory
protected

Definition at line 24 of file CustomerExtractor.php.

◆ $customerGroupManagement

$customerGroupManagement
protected

Definition at line 34 of file CustomerExtractor.php.

◆ $dataObjectHelper

$dataObjectHelper
protected

Definition at line 39 of file CustomerExtractor.php.

◆ $formFactory

$formFactory
protected

Definition at line 19 of file CustomerExtractor.php.

◆ $storeManager

$storeManager
protected

Definition at line 29 of file CustomerExtractor.php.


The documentation for this class was generated from the following file: