function commerce_checkout_form_alter in Commerce Core 8.2
Same name and namespace in other branches
- 7 modules/checkout/commerce_checkout.module \commerce_checkout_form_alter()
Implements hook_form_alter().
File
- modules/
checkout/ commerce_checkout.module, line 164 - Provides configurable checkout flows.
Code
function commerce_checkout_form_alter(&$form, FormStateInterface $form_state, $form_id) {
if ($form_state
->getFormObject() instanceof ViewsForm) {
/** @var \Drupal\views\ViewExecutable $view */
$view = reset($form_state
->getBuildInfo()['args']);
// Only add the Checkout button if the cart form view has order items.
if ($view->storage
->get('tag') == 'commerce_cart_form' && !empty($view->result)) {
$form['actions']['checkout'] = [
'#type' => 'submit',
'#value' => t('Checkout'),
'#weight' => 5,
'#access' => \Drupal::currentUser()
->hasPermission('access checkout'),
'#submit' => array_merge($form['#submit'], [
'commerce_checkout_order_item_views_form_submit',
]),
'#order_id' => $view->argument['order_id']->value[0],
'#update_cart' => TRUE,
'#show_update_message' => FALSE,
];
}
}
}