FieldFormatter throwing error with tecnickcom/tc-lib-barcode 2.3

Created on 15 November 2024, about 1 month ago

Problem/Motivation

TypeError: Com\Tecnick\Barcode\Barcode::getBarcodeObj(): Argument #3 ($width) must be of type int, string given, called in /webroot/web/modules/contrib/barcodes/src/Plugin/Field/FieldFormatter/Barcode.php on line 291 in Com\Tecnick\Barcode\Barcode->getBarcodeObj() (line 101 of/webroot/vendor/tecnickcom/tc-lib-barcode/src/Barcode.php).

Version 2.3 of tecnickcom/tc-lib-barcode updated the `getBarcodeObj` method to require integers for width and height.

Steps to reproduce

Composer require module, ensure it's downloading tecnickcom/tc-lib-barcode 2.3. Enable and configure a QR code.
Error will be thrown on display of QR code.

Proposed resolution

Cast width and height to (int) in FieldFormatter/Barcode.php::viewElements().

πŸ› Bug report
Status

Active

Version

2.1

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States srjosh

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @srjosh
  • Pipeline finished with Success
    about 1 month ago
    Total: 254s
    #339251
  • πŸ‡ΊπŸ‡ΈUnited States tr Cascadia

    I can't reproduce this. How did you set the width? Do you see the same error when using the default width?
    What version of Drupal? Are you using Barcodes 2.1.0?

    The field formatter parameters that need to be integers are width, height, padding_top, padding_bottom, padding_right, and padding_left. All of these are defined as integers in the field formatter schema.
    All of these are initialized to integer values.
    All of these use "number" form elements for user input, ensuring that only integers get passed to the code.
    I would expect either all of these show the same error or that none of them show that error.

    I don't see how width can be a string at that point in the code, unless you are setting it by importing a config file. Drupal doesn't enforce types when importing config files, so if your config file is setting the width to a string value then it won't be checked - if that's the case just edit your config file to ensure the width is an integer and not quoted like a string.

  • πŸ‡ΊπŸ‡ΈUnited States tr Cascadia
  • πŸ‡ΊπŸ‡ΈUnited States tr Cascadia

    @srjosh: Is this still a problem? If so please provide the requested information so I can help.

Production build 0.71.5 2024