You are here

function paymentform_field_widget_form in Payment 7

Implements hook_field_widget_form().

File

modules/paymentform/paymentform.module, line 76
Hook implementations and general functions.

Code

function paymentform_field_widget_form(array &$form, array &$form_state, array $field, array $instance, $langcode, array $items, $delta, array $element) {
  global $user;
  $default_value = array();
  foreach ($items as $line_item_data) {
    $default_value[] = new PaymentLineItem($line_item_data);
  }
  if ($instance['widget']['type'] == 'paymentform_line_item') {
    $element = array(
      '#type' => 'value',
      // Use a validation callback to convert the PaymentLineItem objects from
      // the payment_line_item element to arrays usable by Field API.
      '#element_validate' => array(
        'paymentform_field_widget_form_validate',
      ),
    ) + $element;
    $element['line_item'] = array(
      '#type' => 'payment_line_item',
      '#currency_code' => $instance['settings']['currency_code'],
      '#cardinality' => $field['cardinality'] == FIELD_CARDINALITY_UNLIMITED ? 0 : (int) $field['cardinality'],
      '#default_value' => $default_value,
      '#required' => $element['#required'],
    );
  }
  return $element;
}