function barcode_field in Barcode 6
Same name and namespace in other branches
- 6.2 barcodefield.module \barcode_field()
Implementation of hook_field().
File
- ./
barcode.module, line 79
Code
function barcode_field($op, &$node, $field, &$items, $teaser, $page) {
switch ($op) {
case 'validate':
// validate the entered data according to the encoding method.
$encoding = variable_get('barcode_encoding', array(
'UPC-A',
));
foreach ($items as $delta => $item) {
if ($encoding == 'UPC-A') {
//UPC-A length validation
$len = strlen(trim(check_plain($item['barcode'])));
if ($len != 0 && strlen(trim(check_plain($item['title']))) != 0) {
// If a bacode is entered.
if ($len != 12) {
form_set_error($field['field_name'] . '][' . $delta . '][barcode', t('UPC-A code must have 12 digits! Check your #' . ($delta + 1) . ' entry. Length: ' . $len));
}
}
}
}
break;
case 'sanitize':
foreach ($items as $delta => $item) {
$items[$delta]['barcode'] = trim(check_plain($item['barcode']));
$items[$delta]['title'] = trim(check_plain($item['title']));
}
break;
}
}