function theme_barcode_formatter_default in Barcode 6
Same name and namespace in other branches
- 6.2 barcodefield.module \theme_barcode_formatter_default()
Theme function for 'default' barcode field formatter.
File
- ./
barcode.module, line 145
Code
function theme_barcode_formatter_default($element) {
if (!empty($element['#item']['barcode'])) {
// First to check if the images has been generated from preview request
$path = variable_get('barcode_default_path', 'barcodes');
$encoding = variable_get('barcode_encoding', 'UPC-A');
$filename = file_create_path($path) . '/' . $element['#item']['barcode'] . $encoding . '.png';
if (!file_exists($filename)) {
include_once drupal_get_path('module', 'barcode') . '/barcode.inc.php';
$bar = new BARCODE();
$type = 'png';
$bar
->setSymblogy($encoding);
$bar
->setHeight(variable_get('barcode_height', 30));
$bar
->setScale(variable_get('barcode_scale', 2.0));
$bar
->setHexColor(variable_get('barcode_bcolor', '#000000'), variable_get('barcode_barcolor', '#FFFFFF'));
$bar
->setFont(variable_get('barcode_font', drupal_get_path('module', 'barcode') . "/arialbd.ttf"));
$bar
->genBarCode($element['#item']['barcode'], $type, file_create_path($path) . '/' . $element['#item']['barcode'] . $encoding);
drupal_set_message(t('The barcode image for %barcode has been generated, using %encoding.', array(
'%barcode' => $element['#item']['barcode'],
'%encoding' => $encoding,
)));
}
$path = variable_get('barcode_default_path', 'barcodes');
if (!empty($element['#item']['title'])) {
return '<img src="/' . base_path() . url($filename) . '" alt="' . $element['#item']['barcode'] . '" /> -- ' . $element['#item']['title'];
}
else {
return '<img src="/' . base_path() . url($filename) . '" alt="' . $element['#item']['barcode'] . '" />';
}
}
else {
return '';
}
}