function barcodes_block_view in Barcodes 7
Implements hook_block_view().
File
- ./
barcodes.module, line 138 - Contains barcodes.module.
Code
function barcodes_block_view($delta = '') {
// This example is adapted from node.module.
$block = array();
switch ($delta) {
case 'barcode':
$block['subject'] = t('Barcode');
$generator = new BarcodeGenerator();
$suffix = str_replace('+', 'plus', strtolower(variable_get('barcodes_type', 'QRCODE')));
$value = variable_get('barcodes_value', '');
if (module_exists('token')) {
$value = token_replace($value);
}
$block['content'] = array(
'#theme' => 'barcode__' . $suffix,
'#attached' => array(
'css' => array(
drupal_get_path('module', 'barcodes') . '/css/' . $suffix . '.css',
),
),
'#type' => variable_get('barcodes_type', 'QRCODE'),
'#value' => check_plain($value),
'#width' => variable_get('barcodes_width', 100),
'#height' => variable_get('barcodes_height', 100),
'#color' => variable_get('barcodes_color', '#000000'),
'#padding_top' => variable_get('barcodes_padding_top', 0),
'#padding_right' => variable_get('barcodes_padding_right', 0),
'#padding_bottom' => variable_get('barcodes_padding_bottom', 0),
'#padding_left' => variable_get('barcodes_padding_left', 0),
'#show_value' => variable_get('barcodes_show_value', FALSE),
);
try {
$barcode = $generator
->getBarcodeObj(variable_get('barcodes_type', 'QRCODE'), $value, variable_get('barcodes_width', 100), variable_get('barcodes_height', 100), variable_get('barcodes_color', '#000000'), array(
variable_get('barcodes_padding_top', 0),
variable_get('barcodes_padding_right', 0),
variable_get('barcodes_padding_bottom', 0),
variable_get('barcodes_padding_left', 0),
));
$block['content']['#svg'] = $barcode
->getSvgCode();
} catch (\Exception $e) {
watchdog('barcodes', 'Error: @error, given: @value', array(
'@error' => $e
->getMessage(),
'@value' => $value,
));
}
break;
}
return $block;
}