protected function CustomerProfile::buildOptions in Commerce Core 8.2
Builds the list of options for the given address book profiles.
Adds the special _original and _new options.
Parameters
\Drupal\profile\Entity\ProfileInterface[] $address_book_profiles: The address book profiles.
Return value
array The profile options.
1 call to CustomerProfile::buildOptions()
- CustomerProfile::buildInlineForm in modules/
order/ src/ Plugin/ Commerce/ InlineForm/ CustomerProfile.php - Builds the inline form.
File
- modules/
order/ src/ Plugin/ Commerce/ InlineForm/ CustomerProfile.php, line 483
Class
- CustomerProfile
- Provides an inline form for managing a customer profile.
Namespace
Drupal\commerce_order\Plugin\Commerce\InlineFormCode
protected function buildOptions(array $address_book_profiles) {
$profile_options = EntityHelper::extractLabels($address_book_profiles);
// The customer profile is not new, indicating that it is being edited.
// Add an _original option to allow the customer to revert their changes
// after selecting a different option.
if (!$this->entity
->isNew()) {
$profile_options['_original'] = $this->entity
->label();
$address_book_profile_id = $this->entity
->getData('address_book_profile_id', 0);
if (isset($address_book_profiles[$address_book_profile_id])) {
$source_address_book_profile = $address_book_profiles[$address_book_profile_id];
if ($source_address_book_profile
->equalToProfile($this->entity)) {
// Avoid having two identical options in the list.
// Keep the address book option because it is sorted.
unset($profile_options['_original']);
}
else {
// There are two identical options in the list, but their profiles
// are no longer identical. Add a suffix to the _original version
// to help the customer differentiate.
if ($profile_options['_original'] == $source_address_book_profile
->label()) {
$profile_options['_original'] = $this
->t('@profile (current version)', [
'@profile' => $this->entity
->label(),
]);
}
// Don't update the address book profile, since it is out of sync.
$this->entity
->setData('copy_to_address_book', FALSE);
}
}
}
$profile_options['_new'] = $this
->t('+ Enter a new address');
return $profile_options;
}