You are here

public function Barcode::filterBarcode in Barcodes 2.0.x

Same name and namespace in other branches
  1. 8 src/Template/Barcode.php \Drupal\barcodes\Template\Barcode::filterBarcode()

Barcode filter.

Parameters

string $value: The string that should be formatted as a barcode.

string $type: The barcode type.

string $color: The barcode color.

int $height: The barcode height.

int $width: The barcode width.

int $padding_top: The barcode top padding.

int $padding_right: The barcode right padding.

int $padding_bottom: The barcode bottom padding.

int $padding_left: The barcode left padding.

Return value

string The barcode markup to display.

Throws

\Com\Tecnick\Barcode\Exception

File

src/Template/Barcode.php, line 88

Class

Barcode
Provides a "barcode" Twig filter for formatting text as a barcode.

Namespace

Drupal\barcodes\Template

Code

public function filterBarcode($value, $type = 'QRCODE', $color = '#000000', $height = 100, $width = 100, $padding_top = 0, $padding_right = 0, $padding_bottom = 0, $padding_left = 0) {
  $value = (string) $value;
  $generator = new BarcodeGenerator();
  $value = $this->token
    ->replace($value);
  $barcode = $generator
    ->getBarcodeObj($type, $value, $width, $height, $color, [
    $padding_top,
    $padding_right,
    $padding_bottom,
    $padding_left,
  ]);
  return $barcode
    ->getSvgCode();
}