You are here

class Barcode in Barcodes 8

Same name in this branch
  1. 8 src/Template/Barcode.php \Drupal\barcodes\Template\Barcode
  2. 8 src/Plugin/Block/Barcode.php \Drupal\barcodes\Plugin\Block\Barcode
  3. 8 src/Plugin/Field/FieldFormatter/Barcode.php \Drupal\barcodes\Plugin\Field\FieldFormatter\Barcode
Same name and namespace in other branches
  1. 2.0.x src/Template/Barcode.php \Drupal\barcodes\Template\Barcode

Class Barcode.

@package Drupal\barcodes\Template

Hierarchy

  • class \Drupal\barcodes\Template\Barcode extends \Drupal\barcodes\Template\Twig_Extension

Expanded class hierarchy of Barcode

1 string reference to 'Barcode'
barcodes.services.yml in ./barcodes.services.yml
barcodes.services.yml
1 service uses Barcode
barcodes.twig_extension in ./barcodes.services.yml
\Drupal\barcodes\Template\Barcode

File

src/Template/Barcode.php, line 12

Namespace

Drupal\barcodes\Template
View source
class Barcode extends \Twig_Extension {

  /**
   * {@inheritdoc}
   */
  public function getName() {
    return 'barcode';
  }

  /**
   * {@inheritdoc}
   */
  public function getFilters() {
    return [
      new \Twig_SimpleFilter('barcode', [
        $this,
        'filterBarcode',
      ], [
        'is_safe' => [
          'html',
        ],
      ]),
    ];
  }

  /**
   * Barcode filter.
   *
   * @param string $value
   *   The string that should be formatted as a barcode.
   * @param string $type
   *   The barcode type.
   * @param string $color
   *   The barcode color.
   * @param int $height
   *   The barcode height.
   * @param int $width
   *   The barcode width.
   * @param int $padding_top
   *   The barcode top padding.
   * @param int $padding_right
   *   The barcode right padding.
   * @param int $padding_bottom
   *   The barcode bottom padding.
   * @param int $padding_left
   *   The barcode left padding.
   *
   * @return string
   *   The barcode markup to display.
   *
   * @throws \Com\Tecnick\Barcode\Exception
   */
  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 = \Drupal::token()
      ->replace($value);
    $barcode = $generator
      ->getBarcodeObj($type, $value, $width, $height, $color, [
      $padding_top,
      $padding_right,
      $padding_bottom,
      $padding_left,
    ]);
    return $barcode
      ->getSvgCode();
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Barcode::filterBarcode public function Barcode filter.
Barcode::getFilters public function
Barcode::getName public function