I have custom API that creates new Customer profiles with different addresses / emails:

        'type' => 'customer',
        'uid' => $this->currentUser->id(),
        'status'=> 1,
        'address' => $addressData

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.

enter image description here


It seems this error actually occurs at $entity->validate(), not on save()

enter image description here

This is the contents of core.entity_form_display.profile.customer.default.yml

uuid: xxx7f0e2-d809-4d2b-9388-af399c98xxxx
langcode: en
status: true
    - field.field.profile.customer.address
    - field.field.profile.customer.field_email
    - profile.type.customer
    - address
      - commerce_order
  default_config_hash: xxxxVkJkUSPhil9xxxxdTivMqxCUloT_71AHWxxxx
id: profile.customer.default
targetEntityType: profile
bundle: customer
mode: default
    type: address_default
    weight: 0
    region: content
    settings: {  }
    third_party_settings: {  }
    type: email_default
    weight: 1
    region: content
      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
      - commerce_order
    customer_profile_type: true
  default_config_hash: xxxxAQDUxxxxwavxxxxlcbJx9xxxxFtCq8l73Axxxx
id: customer
label: Customer
display_label: 'Customer information'
multiple: true
registration: false
  authenticated: authenticated
  verified_email: verified_email
  verified_cc: verified_cc
allow_revisions: false
new_revision: false

That setting means the customer may have multiple profiles of that type assigned to their uid, not that every profile reference field can itself be used for multiple value references. That said, I'm not aware of a field in Commerce Core called customer_profiles. Is this something custom? You might just need to update its definition to be able to put multiple references in it.

  • so am I creating / attaching the Profile incorrectly? My goal is that "the customer may have multiple profiles of that type assigned to their uid".
    – E.A.T
    Jan 10 at 15:48
  • Also, I think "customer_profiles" is just the machine name from creating a Profile Type called "Customers". What are you exactly suggesting I update?
    – E.A.T
    Jan 10 at 15:51
  • You have a field on your site called "Customer profiles". Where did that come from? Jan 11 at 16:14
  • I posted my yml files if that might help. Also discovered the error occurs on $user->validate() not $user->save()
    – E.A.T
    Jan 11 at 22:31
  • Also the Customer Profiles is a Profile Type not a field, provided by Commerce: docs.drupalcommerce.org/commerce2/developer-guide/customers/… - along with its field_address. I added afield_email.
    – E.A.T
    Jan 11 at 22:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.