function commerce_cart_form_commerce_order_form_alter in Commerce Core 8.2
Implements hook_form_BASE_FORM_ID_alter() for 'commerce_order_form'.
File
- modules/
cart/ commerce_cart.module, line 201 - Implements the shopping cart system and add to cart features.
Code
function commerce_cart_form_commerce_order_form_alter(array &$form, FormStateInterface $form_state) {
if (isset($form['cart'])) {
/** @var \Drupal\commerce_order\Entity\OrderInterface $order */
$order = $form_state
->getFormObject()
->getEntity();
if ($order
->getState()
->getId() == 'draft') {
// Move the cart element to the bottom of the meta sidebar container.
$form['cart']['#group'] = 'meta';
$form['cart']['#weight'] = 100;
}
else {
// Only draft orders can be carts.
$form['cart']['#type'] = 'hidden';
$form['#default_value'] = FALSE;
}
}
}