16 use Magento\Customer\Model\FileProcessorFactory;
19 use Magento\Customer\Model\ResourceModel\Customer\CollectionFactory as CustomerCollectionFactory;
67 private $countryWithWebsiteSource;
79 'dataType' =>
'frontend_input',
80 'visible' =>
'is_visible',
81 'required' =>
'is_required',
82 'label' =>
'frontend_label',
83 'sortOrder' =>
'sort_order',
85 'default' =>
'default_value',
86 'size' =>
'multiline_count',
97 'boolean' =>
'checkbox',
114 private $fileProcessorFactory;
121 private $fileUploaderTypes = [
131 private $forbiddenCustomerFields = [
147 private $allowToShowHiddenAttributes;
169 CustomerCollectionFactory $customerCollectionFactory,
172 FileProcessorFactory $fileProcessorFactory =
null,
176 $allowToShowHiddenAttributes =
true 180 $this->collection = $customerCollectionFactory->create();
181 $this->collection->addAttributeToSelect(
'*');
184 $this->fileProcessorFactory = $fileProcessorFactory ?: $this->getFileProcessorFactory();
186 $this->allowToShowHiddenAttributes = $allowToShowHiddenAttributes;
188 $this->eavConfig->getEntityType(
'customer')
191 $this->eavConfig->getEntityType(
'customer_address')
204 if ($this->session ===
null) {
219 if (isset($this->loadedData)) {
222 $items = $this->collection->getItems();
229 $result[
'customer'] = array_diff_key(
231 array_flip($this->forbiddenCustomerFields)
242 $this->overrideFileUploaderData(
$address,
$result[
'address'][$addressId]);
266 private function overrideFileUploaderData(
$entity, array &$entityData)
271 if (in_array(
$attribute->getFrontendInput(), $this->fileUploaderTypes)) {
272 $entityData[
$attribute->getAttributeCode()] = $this->getFileUploaderData(
290 private function getFileUploaderData(
302 $fileProcessor = $this->getFileProcessorFactory()->create([
303 'entityTypeCode' =>
$entityType->getEntityTypeCode(),
307 && $fileProcessor->isExist($file)
309 $stat = $fileProcessor->getStat($file);
310 $viewUrl = $fileProcessor->getViewUrl($file,
$attribute->getFrontendInput());
315 'size' => isset($stat) ? $stat[
'size'] : 0,
316 'url' => isset($viewUrl) ? $viewUrl :
'',
317 'name' => basename($file),
318 'type' => $fileProcessor->getMimeType($file),
344 foreach ($this->metaProperties as $metaName => $origName) {
347 if (
'frontend_input' === $origName) {
348 $meta[
$code][
'arguments'][
'data'][
'config'][
'formElement'] = isset($this->formElement[
$value])
349 ? $this->formElement[
$value]
356 $meta[
$code][
'arguments'][
'data'][
'config'][
'options'] = $this->getCountryWithWebsiteSource()
359 $meta[
$code][
'arguments'][
'data'][
'config'][
'options'] =
$attribute->getSource()->getAllOptions();
368 $meta[
$code][
'arguments'][
'data'][
'config'][
'componentType'] = Field::NAME;
374 $this->processWebsiteMeta(
$meta);
388 if ($customerAttribute->
getEntityType()->getEntityTypeCode() ===
'customer') {
389 return is_array($customerAttribute->getUsedInForms()) &&
391 (in_array(
'customer_account_create', $customerAttribute->getUsedInForms()) && $isRegistration) ||
392 (in_array(
'customer_account_edit', $customerAttribute->getUsedInForms()) && !$isRegistration)
395 return is_array($customerAttribute->getUsedInForms()) &&
396 in_array(
'customer_address_edit', $customerAttribute->getUsedInForms());
406 private function canShowAttribute(AbstractAttribute $customerAttribute)
408 $userDefined = (bool) $customerAttribute->getIsUserDefined();
410 return $customerAttribute->getIsVisible();
413 $canShowOnForm = $this->canShowAttributeInForm($customerAttribute);
415 return ($this->allowToShowHiddenAttributes && $canShowOnForm) ||
416 (!$this->allowToShowHiddenAttributes && $canShowOnForm && $customerAttribute->getIsVisible());
425 private function getCountryWithWebsiteSource()
427 if (!$this->countryWithWebsiteSource) {
431 return $this->countryWithWebsiteSource;
440 private function getShareConfig()
442 if (!$this->shareConfig) {
446 return $this->shareConfig;
455 private function processWebsiteMeta(&
$meta)
463 'target' =>
'${ $.provider }:data.customer.website_id',
464 'field' =>
'website_ids' 479 private function overrideFileUploaderMetadata(
484 if (in_array(
$attribute->getFrontendInput(), $this->fileUploaderTypes)) {
487 if (isset(
$config[
'validation'][
'max_file_size'])) {
488 $maxFileSize = (int)
$config[
'validation'][
'max_file_size'];
493 if (isset(
$config[
'validation'][
'file_extensions'])) {
506 'formElement' =>
'fileUploader',
507 'componentType' =>
'fileUploader',
508 'maxFileSize' => $maxFileSize,
510 'uploaderConfig' => [
513 'label' => $this->getMetadataValue(
$config,
'label'),
514 'sortOrder' => $this->getMetadataValue(
$config,
'sortOrder'),
515 'required' => $this->getMetadataValue(
$config,
'required'),
516 'visible' => $this->getMetadataValue(
$config,
'visible'),
517 'validation' => $this->getMetadataValue(
$config,
'validation'),
530 private function getMetadataValue(
$config,
$name, $default =
null)
546 $url =
'customer/file/customer_upload';
550 $url =
'customer/file/address_upload';
567 private function processFrontendInput(AttributeInterface
$attribute, array &
$meta)
570 if (
$attribute->getFrontendInput() ===
'boolean') {
571 $meta[
$code][
'arguments'][
'data'][
'config'][
'prefer'] =
'toggle';
572 $meta[
$code][
'arguments'][
'data'][
'config'][
'valueMap'] = [
590 && $addressId ==
$customer[
'default_billing']
595 && $addressId ==
$customer[
'default_shipping']
610 private function getFileProcessorFactory()
612 if ($this->fileProcessorFactory ===
null) {
616 return $this->fileProcessorFactory;
__construct( $name, $primaryFieldName, $requestFieldName, EavValidationRules $eavValidationRules, CustomerCollectionFactory $customerCollectionFactory, Config $eavConfig, FilterPool $filterPool, FileProcessorFactory $fileProcessorFactory=null, array $meta=[], array $data=[], ContextInterface $context=null, $allowToShowHiddenAttributes=true)
prepareAddressData($addressId, array &$addresses, array $customer)
getAttributesMeta(Type $entityType)