You are here

function commerce_paypal_checkout_form_alter in Commerce PayPal 7.2

Implements hook_form_alter().

File

modules/checkout/commerce_paypal_checkout.module, line 852
Implements PayPal Checkout in Drupal Commerce checkout.

Code

function commerce_paypal_checkout_form_alter(&$form, &$form_state, $form_id) {
  if (!is_string($form_id)) {
    return;
  }

  // If we're altering a shopping cart form.
  if (strpos($form_id, 'views_form_commerce_cart_form_') === 0) {

    // If the cart form View shows line items...
    if (!empty($form_state['build_info']['args'][0]->result)) {
      $order = $form_state['order'];
      $payment_method = commerce_paypal_checkout_get_payment_method_instance($order);

      // If no PayPal checkout payment method is configured, or if the buttons
      // are explicitly not shown on the cart page, stop here.
      if (!$payment_method || empty($payment_method['settings']['enable_on_cart'])) {
        return;
      }
      $form['smart_payment_buttons'] = array(
        '#theme' => 'commerce_paypal_checkout_smart_payment_buttons',
        '#payment_method' => $payment_method,
        '#commit' => FALSE,
        '#flow' => 'shortcut',
        '#order' => $order,
        '#weight' => 100,
      );
    }
  }
}