Commit e205755d authored by Łukasz Zaroda's avatar Łukasz Zaroda Committed by Bart Feenstra
Browse files

Issue #2316281 by Xano, Luke_Nuke: Move "amount" input and submit button to bottom of the form

parent 1ebaea19
Loading
Loading
Loading
Loading
+26 −6
Changes for payment_donation.module: 26 added lines, 6 removed lines.
Original line number Diff line number Diff line
@@ -91,6 +91,23 @@ function payment_donation_block_view($delta = '') {
  }
}

/**
 * Implements hook_field_extra_fields().
 */
function payment_donation_field_extra_fields() {
  $fields['payment']['payment'] = array(
    'form' => array(
      'payment_donation_amount' => array(
        'label' => t('Payment amount (Payment donation form)'),
        'description' => '',
        'weight' => 99,
      ),
    ),
  );

  return $fields;
}

/**
 * Implements form build callback: the donation form.
 */
@@ -107,17 +124,17 @@ function payment_donation_form(array $form, array &$form_state) {

  $payment_method = entity_load_single('payment_method', $pmid);

  $form['amount'] = array(
  $form['payment_donation_amount'] = array(
    '#currency_code' => $currency_code,
    '#title' => t('Amount'),
    '#type' => 'currency_amount',
  );
  $currencies = $payment_method->controller->currencies;
  if (isset($currencies[$currency_code]['minimum'])) {
    $form['amount']['#minimum_amount'] = $currencies[$currency_code]['minimum'];
    $form['payment_donation_amount']['#minimum_amount'] = $currencies[$currency_code]['minimum'];
  }
  if (isset($currencies[$currency_code]['maximum'])) {
    $form['amount']['#maximum_amount'] = $currencies[$currency_code]['maximum'];
    $form['payment_donation_amount']['#maximum_amount'] = $currencies[$currency_code]['maximum'];
  }

  $payment = new Payment(array(
@@ -136,7 +153,10 @@ function payment_donation_form(array $form, array &$form_state) {
  $form = array_merge($form, $form_info['elements']);
  $form['#validate'][] = 'payment_donation_form_validate';

  $form['pay'] = array(
  $form['actions'] = array(
    '#type' => 'actions',
  );
  $form['actions']['payment_donation_pay'] = array(
    '#value' => t('Pay'),
    '#type' => 'submit',
    '#submit' => array_merge($form_info['submit'], array('payment_donation_form_submit')),
@@ -151,7 +171,7 @@ function payment_donation_form(array $form, array &$form_state) {
function payment_donation_form_validate(array $form, array &$form_state) {
  /** @var Payment $payment */
  $payment =& $form_state['payment'];
  $amount = $form_state['values']['amount']['amount'];
  $amount = $form_state['values']['payment_donation_amount']['amount'];
  $payment->setLineItem(new PaymentLineItem(array(
    'amount' => $amount,
    'description' => variable_get('payment_donation_payment_description', ''),
@@ -163,7 +183,7 @@ function payment_donation_form_validate(array $form, array &$form_state) {
  }
  catch (PaymentValidationException $e) {
    $message = strlen($e->getMessage()) ? $e->getMessage() : t('The payment cannot be executed.');
    form_error($form['amount'], $message);
    form_error($form['payment_donation_amount'], $message);
  }
}