public function ShipmentEditForm::submitForm in Ubercart 8.4
Form submission handler.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Overrides FormInterface::submitForm
File
- shipping/
uc_fulfillment/ src/ Form/ ShipmentEditForm.php, line 303
Class
- ShipmentEditForm
- Creates or edits a shipment.
Namespace
Drupal\uc_fulfillment\FormCode
public function submitForm(array &$form, FormStateInterface $form_state) {
$this->shipment
->setOrderId($this->order_id);
// The pickup_address and delivery_address form elements are defined in AddressForm.
$this->shipment
->setOrigin(Address::create($form_state
->getValue('pickup_address')));
$this->shipment
->setDestination(Address::create($form_state
->getValue('delivery_address')));
$packages = [];
foreach ($form_state
->getValue('packages') as $id => $pkg_form) {
$package = Package::load($id);
$package
->setPackageType($pkg_form['pkg_type']);
$package
->setValue($pkg_form['declared_value']);
$package
->setTrackingNumber($pkg_form['tracking_number']);
$package
->setWeight($pkg_form['weight']['weight']);
$package
->setWeightUnits($pkg_form['weight']['units']);
$package
->setLength($pkg_form['dimensions']['length']);
$package
->setWidth($pkg_form['dimensions']['width']);
$package
->setHeight($pkg_form['dimensions']['height']);
$package
->setLengthUnits($pkg_form['dimensions']['units']);
$packages[$id] = $package;
}
$this->shipment
->setPackages($packages);
$this->shipment
->setCarrier($form_state
->getValue('carrier'));
$this->shipment
->setShippingMethod($form_state
->getValue('shipping_method'));
$this->shipment
->setAccessorials($form_state
->getValue('accessorials'));
$this->shipment
->setTransactionId($form_state
->getValue('transaction_id'));
$this->shipment
->setTrackingNumber($form_state
->getValue('tracking_number'));
$this->shipment
->setShipDate($form_state
->getValue('ship_date')
->getTimestamp());
$this->shipment
->setExpectedDelivery($form_state
->getValue('expected_delivery')
->getTimestamp());
$this->shipment
->setCost($form_state
->getValue('cost'));
$this->shipment
->save();
$form_state
->setRedirect('uc_fulfillment.shipments', [
'uc_order' => $this->order_id,
]);
}