You are here

function paymentform_field_validate in Payment 7

Implements hook_field_validate().

File

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

Code

function paymentform_field_validate($entity_type, $entity, $field, $instance, $langcode, $items, &$errors) {
  if ($field['type'] == 'paymentform') {
    foreach ($items as $delta => $line_item_data) {
      $base = array(
        'delta' => $delta,
      );

      // Amount.
      $base['property'] = 'amount';
      if (!is_float($line_item_data['amount'])) {
        $errors[$field['field_name']][$langcode][$delta][] = array(
          'error' => 'paymentform_line_item_amount_no_float',
          'message' => t('The amount is no floating point.'),
        ) + $base;
      }

      // Quantity.
      $base['property'] = 'quantity';
      if (!is_int($line_item_data['quantity'])) {
        $errors[$field['field_name']][$langcode][$delta][] = array(
          'error' => 'paymentform_line_item_quantity_no_integer',
          'message' => t('The quantity is no integer.'),
        ) + $base;
      }
      elseif ($line_item_data['quantity'] < 0) {
        $errors[$field['field_name']][$langcode][$delta][] = array(
          'error' => 'paymentform_line_item_quantity_negative',
          'message' => t('The quantity cannot be negative.'),
        ) + $base;
      }

      // Tax rate.
      $base['property'] = 'tax_rate';
      if (!is_float($line_item_data['tax_rate'])) {
        $errors[$field['field_name']][$langcode][$delta][] = array(
          'error' => 'paymentform_line_item_tax_rate_no_float',
          'message' => t('The tax rate is no floating point.'),
        ) + $base;
      }
      elseif ($line_item_data['tax_rate'] < 0) {
        $errors[$field['field_name']][$langcode][$delta][] = array(
          'error' => 'paymentform_line_item_tax_rate_negative',
          'message' => t('The tax rate cannot be negative.'),
        ) + $base;
      }

      // Machine name.
      $base['property'] = 'name';
      if (empty($line_item_data['name'])) {
        $errors[$field['field_name']][$langcode][$delta][] = array(
          'error' => 'paymentform_line_item_name_empty',
          'message' => t('The machine-readable name is empty.'),
        ) + $base;
      }
    }
  }
}