function civicrm_entity_discount_field_field_validate in CiviCRM Entity 7.2
Implements hook_field_validate().
File
- modules/
civicrm_entity_discount/ civicrm_entity_discount_field.module, line 259 - Provide CiviCRM Entity Discount Field Type. Provides a widget for selecting custom discount options
Code
function civicrm_entity_discount_field_field_validate($entity_type, $entity, $field, $instance, $langcode, $items, &$errors) {
if ($field['type'] == 'civicrm_entity_discount_field') {
foreach ($items as $delta => $item) {
if (!empty($item['price_field_id'])) {
if (empty($item['discount'])) {
$errors[$field['field_name']][$langcode][$delta][] = array(
'error' => 'civicrm_entity_discount_field_discount_required',
'message' => t('Discount must have value if you select a price field'),
);
}
if (empty($item['discount_type'])) {
$errors[$field['field_name']][$langcode][$delta][] = array(
'error' => 'civicrm_entity_discount_field_discount_type_required',
'message' => t('Discount type must have value if you select a price field'),
);
}
}
if (!empty($item['discount']) && !is_numeric($item['discount'])) {
$errors[$field['field_name']][$langcode][$delta][] = array(
'error' => 'civicrm_entity_discount_field_discount_non_numeric',
'message' => t('Discount must be a numeric value'),
);
}
}
}
}