public function ShipmentInlineForm::entityForm in Commerce Shipping 8.2
Builds the entity form.
Parameters
array $entity_form: The entity form, containing the following basic properties:
- #entity: The entity for the current entity form.
- #op: The form operation. 'add' or 'edit'.
- #form_mode: The form mode used to display the entity form.
- #parents: Identifies the position of the entity form in the overall parent form, and identifies the location where the field values are placed within $form_state->getValues().
\Drupal\Core\Form\FormStateInterface $form_state: The form state of the parent form.
Overrides EntityInlineForm::entityForm
File
- src/
Form/ ShipmentInlineForm.php, line 30
Class
- ShipmentInlineForm
- Defines the inline form for shipments.
Namespace
Drupal\commerce_shipping\FormCode
public function entityForm(array $entity_form, FormStateInterface $form_state) {
$shipment = $entity_form['#entity'];
assert($shipment instanceof ShipmentInterface);
if ($shipment
->isNew()) {
$form_object = $form_state
->getFormObject();
assert($form_object instanceof OrderForm);
$order = $form_object
->getEntity();
assert($order instanceof OrderInterface);
$shipment
->set('order_id', $order);
}
$entity_form = parent::entityForm($entity_form, $form_state);
// IEF + InlineForms (CustomerProfile) are not compatible when the IEF form
// is saved/closed. So we disable the "Update" option.
// @todo remove when IEF + InlineForms are compatible.
if (!$shipment
->isNew()) {
$entity_form['#after_build'][] = [
static::class,
'disableSaveButton',
];
}
return $entity_form;
}