diff --git a/modules/order/src/Element/ProfileSelect.php b/modules/order/src/Element/ProfileSelect.php
index 34de1a4d..7415729c 100644
--- a/modules/order/src/Element/ProfileSelect.php
+++ b/modules/order/src/Element/ProfileSelect.php
@@ -156,7 +156,7 @@ class ProfileSelect extends RenderElement {
$selected_option = $element_state['selected_option'];
}
elseif ($default_profile = self::selectDefaultProfile($element, $profiles)) {
- $selected_option = self::buildOptionId($default_profile, $element['#profile_latest_revision']);
+ $selected_option = self::buildOptionId($default_profile, $element['#profile_latest_revision']);
}
$id_parts = explode('-', $selected_option);
if (!empty($id_parts[1])) {
@@ -171,58 +171,82 @@ class ProfileSelect extends RenderElement {
'uid' => $element['#profile_uid'],
]);
}
- $id_prefix = implode('-', $element['#parents']);
- $wrapper_id = Html::getUniqueId("$id_prefix-ajax-wrapper");
- // Pass the id along to other methods.
- $element['#wrapper_id'] = $wrapper_id;
- $view_builder = \Drupal::entityTypeManager()->getViewBuilder('profile');
- $element['profile_selection'] = [
- '#prefix' => "
",
- '#type' => 'select',
- '#title' => $element['#title'],
- '#options' => $profile_options,
- '#default_value' => $selected_option,
- '#ajax' => [
- 'callback' => [get_called_class(), 'ajaxRefresh'],
- 'wrapper' => $wrapper_id,
- ],
- '#limit_validation_errors' => [],
- '#weight' => -1,
- '#access' => !empty($profile_options),
- ];
- $element['profile'] = $view_builder->view($element['#profile'], 'default');
- $element['profile']['#suffix'] = '
';
- $url = Url::fromRoute('entity.profile.type.user_profile_form.add', ['user' => $element['#profile']->getOwnerId(), 'profile_type' => 'customer']);
- $url->mergeOptions(['query' => \Drupal::destination()->getAsArray()]);
- $element['new'] = [
- '#type' => 'link',
- '#url' => $url,
- '#title' => t('Add new profile'),
- '#attributes' => [
- 'class' => ['use-ajax'],
- 'data-dialog-type' => 'modal',
- 'data-dialog-options' => json_encode([
- 'width' => 700,
- ]),
- ],
- ];
- if (!$element['#profile']->isNew()) {
- $url = Url::fromRoute('entity.profile.edit_form', ['profile' => $element['#profile']->id()]);
+ if (count($profiles) > 0) {
+ $id_prefix = implode('-', $element['#parents']);
+ $wrapper_id = Html::getUniqueId("$id_prefix-ajax-wrapper");
+ // Pass the id along to other methods.
+ $element['#wrapper_id'] = $wrapper_id;
+ $view_builder = \Drupal::entityTypeManager()->getViewBuilder('profile');
+ $element['profile_selection'] = [
+ '#prefix' => "",
+ '#type' => 'select',
+ '#title' => $element['#title'],
+ '#options' => $profile_options,
+ '#default_value' => $selected_option,
+ '#ajax' => [
+ 'callback' => [get_called_class(), 'ajaxRefresh'],
+ 'wrapper' => $wrapper_id,
+ ],
+ '#limit_validation_errors' => [],
+ '#weight' => -1,
+ '#access' => !empty($profile_options),
+ ];
+ $element['profile'] = $view_builder->view($element['#profile'], 'default');
+ $element['profile']['#suffix'] = '
';
+ $url = Url::fromRoute('entity.profile.type.user_profile_form.add', ['user' => $element['#profile']->getOwnerId(), 'profile_type' => 'customer']);
$url->mergeOptions(['query' => \Drupal::destination()->getAsArray()]);
- $element['edit'] = [
+ $element['new'] = [
'#type' => 'link',
'#url' => $url,
- '#title' => t('Edit profile'),
+ '#title' => t('Add new profile'),
'#attributes' => [
- 'class' => ['use-ajax'],
+ 'class' => [
+ 'use-ajax',
+ 'button',
+ ],
'data-dialog-type' => 'modal',
'data-dialog-options' => json_encode([
'width' => 700,
]),
],
];
+ if (!$element['#profile']->isNew()) {
+ $url = Url::fromRoute('entity.profile.edit_form', ['profile' => $element['#profile']->id()]);
+ $url->mergeOptions(['query' => \Drupal::destination()->getAsArray()]);
+ $element['edit'] = [
+ '#type' => 'link',
+ '#url' => $url,
+ '#title' => t('Edit profile'),
+ '#attributes' => [
+ 'class' => [
+ 'use-ajax',
+ 'button',
+ ],
+ 'data-dialog-type' => 'modal',
+ 'data-dialog-options' => json_encode([
+ 'width' => 700,
+ ]),
+ ],
+ ];
+ }
+ $element['#attached']['library'][] = 'core/drupal.dialog.ajax';
+ } else {
+ $form_display = EntityFormDisplay::collectRenderDisplay($element['#profile'], 'default');
+ $form_display->buildForm($element['#profile'], $element, $form_state);
+ if (!empty($element['address']['widget'][0])) {
+ $widget_element = &$element['address']['widget'][0];
+ // Remove the details wrapper from the address widget.
+ $widget_element['#type'] = 'container';
+ // Provide a default country.
+ if (!empty($element['#default_country']) && empty($widget_element['address']['#default_value']['country_code'])) {
+ $widget_element['address']['#default_value']['country_code'] = $element['#default_country'];
+ }
+ // Limit the available countries.
+ if (!empty($element['#available_countries'])) {
+ $widget_element['address']['#available_countries'] = $element['#available_countries'];
+ }
+ }
}
- $element['#attached']['library'][] = 'core/drupal.dialog.ajax';
// Persist any changes made to $element_state.
self::setElementState($element['#parents'], $form_state, $element_state);
return $element;