public static function ProfileFieldCopy::submitForm in Commerce Shipping 8.2
Submits the inline form.
Parameters
array $inline_form: The inline form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
File
- src/
ProfileFieldCopy.php, line 214
Class
- ProfileFieldCopy
- Default implementation of profile field copying ("Billing same as shipping").
Namespace
Drupal\commerce_shippingCode
public static function submitForm(array &$inline_form, FormStateInterface $form_state) {
$shipping_fields = $inline_form['copy_fields']['#shipping_fields'];
$shipping_profile = static::getShippingProfile($form_state);
$billing_profile = static::getBillingProfile($inline_form);
$billing_profile
->populateFromProfile($shipping_profile, $shipping_fields);
if ($inline_form['copy_fields']['#has_form']) {
$form_display = static::getFormDisplay($billing_profile, 'billing', $shipping_fields);
$form_display
->extractFormValues($billing_profile, $inline_form['copy_fields'], $form_state);
}
$billing_profile
->setData('copy_fields', TRUE);
$billing_profile
->unsetData('copy_to_address_book');
// Transfer the source address book ID to ensure that the right option
// is preselected when the copy_fields checkbox is unchecked.
$address_book_profile_id = $shipping_profile
->getData('address_book_profile_id');
if ($address_book_profile_id && $shipping_profile
->bundle() == $billing_profile
->bundle()) {
$billing_profile
->setData('address_book_profile_id', $address_book_profile_id);
}
$billing_profile
->save();
}