I have custom API that creates new Customer
profiles with different addresses / emails:
$profileStorage->create([
'type' => 'customer',
'uid' => $this->currentUser->id(),
'status'=> 1,
'address' => $addressData
])
$profile->setDefault(true);
$profile->save();
It works creating those profiles and attaching them to the current user. However, then after whenever I try to edit the user's account fields or just use $user->validate()
I get this error:
"customer_profiles: Customer profiles: this field cannot hold more than 1 values."
However Customer Profile Type has both "Allow multiple profiles per user" and "Profiles of this type represent Commerce customer profiles" selected.
This has been the case in Drupal 8 and 9.
UPDATE:
It seems this error actually occurs at $entity->validate()
, not on save()
This is the contents of core.entity_form_display.profile.customer.default.yml
uuid: xxx7f0e2-d809-4d2b-9388-af399c98xxxx
langcode: en
status: true
dependencies:
config:
- field.field.profile.customer.address
- field.field.profile.customer.field_email
- profile.type.customer
module:
- address
enforced:
module:
- commerce_order
_core:
default_config_hash: xxxxVkJkUSPhil9xxxxdTivMqxCUloT_71AHWxxxx
id: profile.customer.default
targetEntityType: profile
bundle: customer
mode: default
content:
address:
type: address_default
weight: 0
region: content
settings: { }
third_party_settings: { }
field_email:
type: email_default
weight: 1
region: content
settings:
placeholder: ''
size: 60
third_party_settings: { }
hidden: { }
and the contents of profile.type.customer.yml
uuid: xxxx4f32-xxxx-xxxx-xxxx-bd10470bxxxx
langcode: en
status: true
dependencies:
enforced:
module:
- commerce_order
third_party_settings:
commerce_order:
customer_profile_type: true
_core:
default_config_hash: xxxxAQDUxxxxwavxxxxlcbJx9xxxxFtCq8l73Axxxx
id: customer
label: Customer
display_label: 'Customer information'
multiple: true
registration: false
roles:
authenticated: authenticated
verified_email: verified_email
verified_cc: verified_cc
allow_revisions: false
new_revision: false