public function ShippingInformation::submitPaneForm in Commerce Shipping 8.2
Handles the submission of an pane form.
Parameters
array $pane_form: The pane form.
\Drupal\Core\Form\FormStateInterface $form_state: The form state of the parent form.
array $complete_form: The complete form structure.
Overrides CheckoutPaneBase::submitPaneForm
File
- src/
Plugin/ Commerce/ CheckoutPane/ ShippingInformation.php, line 439
Class
- ShippingInformation
- Provides the shipping information pane.
Namespace
Drupal\commerce_shipping\Plugin\Commerce\CheckoutPaneCode
public function submitPaneForm(array &$pane_form, FormStateInterface $form_state, array &$complete_form) {
/** @var \Drupal\commerce\Plugin\Commerce\InlineForm\EntityInlineFormInterface $inline_form */
$inline_form = $pane_form['shipping_profile']['#inline_form'];
/** @var \Drupal\profile\Entity\ProfileInterface $profile */
$profile = $inline_form
->getEntity();
// Save the modified shipments.
$shipments = [];
foreach (Element::children($pane_form['shipments']) as $index) {
if (!isset($pane_form['shipments'][$index]['#shipment'])) {
continue;
}
/** @var \Drupal\commerce_shipping\Entity\ShipmentInterface $shipment */
$shipment = clone $pane_form['shipments'][$index]['#shipment'];
$form_display = EntityFormDisplay::collectRenderDisplay($shipment, 'checkout');
$form_display
->removeComponent('shipping_profile');
$form_display
->extractFormValues($shipment, $pane_form['shipments'][$index], $form_state);
$shipment
->setShippingProfile($profile);
$shipment
->save();
$shipments[] = $shipment;
}
$this->order->shipments = $shipments;
// Delete shipments that are no longer in use.
$removed_shipment_ids = $pane_form['removed_shipments']['#value'];
if (!empty($removed_shipment_ids)) {
$shipment_storage = $this->entityTypeManager
->getStorage('commerce_shipment');
$removed_shipments = $shipment_storage
->loadMultiple($removed_shipment_ids);
$shipment_storage
->delete($removed_shipments);
}
}