You are here

function payment_form_embedded in Payment 7

Builds common elements for a payment add/edit form.

Note that this is not a form build callback and that this function was not designed to be called using drupal_get_form(). Instead, create a real form build callback that calls this function directly.

Parameters

array $form_state:

Payment $payment:

array $pmids: The PMIDs of the payment methods the user is allowed to choose from.

array $parents: An array with the machine names of the form's parent elements.

Return value

array Form information with the following keys:

  • elements: the form's (renderable) elements.
  • submit: an array of form #submit callbacks.

See also

payment_form_standalone()

hook_payment_form_alter()

2 calls to payment_form_embedded()
PaymentTestActionHookAndCallbackWebTestCase::testActionHooksAndCallbacks in tests/payment_test/tests/PaymentTestActionHookAndCallbackWebTestCase.test
Test whether all action hooks and callbacks are invoked.
payment_form_standalone in ./payment.ui.inc
Implements form build callback: the payment add/edit form.

File

./payment.ui.inc, line 76
The Payment user interface.

Code

function payment_form_embedded(array &$form_state, Payment $payment, array $pmids = array(), array $parents = array()) {
  $form_state['payment'] = $payment;
  $elements['#parents'] = $parents;

  // Nest the callback, because if $elements is used as a top-level form render
  // array, #validate will be called instead of #element_validate.
  $elements['validate']['#element_validate'] = array(
    'payment_form_embedded_validate',
  );
  $elements['payment_status'] = array(
    '#access' => !payment_status_is_or_has_ancestor($payment
      ->getStatus()->status, PAYMENT_STATUS_NEW),
    '#type' => 'select',
    '#title' => t('Status'),
    '#options' => payment_status_options(),
    '#default_value' => $payment
      ->getStatus()->status,
    '#required' => TRUE,
    '#description' => t('Updating a payment status manually can disrupt automatic payment processing.') . (user_access('payment.payment_status.view') ? ' ' . l(t('Payment status overview.'), 'admin/config/services/payment/status') : ''),
  );
  $elements['payment_line_items'] = payment_line_items($payment);
  $elements['payment_method'] = array(
    '#access' => payment_status_is_or_has_ancestor($payment
      ->getStatus()->status, PAYMENT_STATUS_NEW),
    '#type' => 'payment_method',
    '#title' => t('Payment method'),
    '#required' => TRUE,
    '#pmids' => $pmids,
  );
  field_attach_form('payment', $payment, $elements, $form_state);
  $submit = array(
    'payment_form_embedded_submit',
  );
  drupal_alter('payment_form', $elements, $form_state, $submit);
  return array(
    'elements' => $elements,
    'submit' => $submit,
  );
}