Generate QR for views field "link to node"

Created on 26 March 2024, 9 months ago

Problem/Motivation

Setup: Drupal 10.2.4 + PHP 8.1.27 + Barcodes 2.0.6

Starting point and target:
Created a view to provide a special format of a node to be printed at the end.
View contains several fields of the node AND should link back from print to the node by a QR Code (to be shown/printed with the view).
All filtering/formatting/context and so on works... but I still do not get the node URL presented as a QR Code.

1st attempt/idea:
In Views I added the "link to node" field, that provides the URL of the respective node... can modify the field in several variations, but can NOT make it a QR Code, as no "formatter" option provided (?)

2nd attemmt/idea:
I added another field "Global: Custom Text" and set "{{ view_node }}" as the custom/replacement text for it... ok - shows again the correct URL of the node, but again NO option to make it a QR Code (?)

Both attempts did not work so far.
Do I miss any important setting to apply a "formatter = barcode" option to the mentioned views fields?
Or do I need to use another field / rewrite magic to provide the node URL as QR Code in a view?

πŸ’¬ Support request
Status

Active

Version

2.0

Component

Miscellaneous

Created by

πŸ‡©πŸ‡ͺGermany windm

Live updates comments and jobs are added and updated live.
  • views

    Involves, uses, or integrates with views. In Drupal 8 core, use the β€œVDC” tag instead.

Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @windm
  • πŸ‡©πŸ‡ͺGermany sanduhrs πŸ‡ͺπŸ‡Ί Heidelberg, Germany, Europe

    at 1. Formatter approach
    I don't think a pseudo field supports formatters.
    You could create a text field or a link field and store the link to the node using a default value and tokens.
    For these kind of fields the barcodes formatter will be available.

    at 2. Global: Custom text
    This also does not support field formatters afaict.
    You could use the twig filter to render the barcode

    {{ view_node|barcode('QRCODE', '#000000', 100, 100, 0, 0, 0, 0, 'png') }}
    

    But currently there is a bug in Drupal core's filter system that prevents rendering if inline data images: https://www.drupal.org/project/drupal/issues/3413396 πŸ› Xss:filter() malforms inline image references with data uri scheme Needs work

  • πŸ‡©πŸ‡ͺGermany sanduhrs πŸ‡ͺπŸ‡Ί Heidelberg, Germany, Europe
  • πŸ‡©πŸ‡ͺGermany windm

    Hi @sanduhrs, thank you for the quick reply.
    OK - got that
    so "workaround" as per #1 would be:
    - introduce a dedicated (text)field to my content-type
    - define the node-URL as the "default value" for it (so I do not even have to show it in the form/edit mode?)
    - I could hide it or show it in the standard display of the node as I like
    - for the "print-view" I could use the field with the formatter "barcode" and make it a qr-code there...

    #2 with the twig filter looks pretty smart, but does not work, as long as the core bug is not fixed...
    to get that right (and maybe move to that solution later), 2 maybe stupid questions:
    - te token you have pasted can simply be used as a replacement token in a Global: Custom text field?
    - does "twig filter" way require the "twig input filter" module (plus mentioned dependencies) to be installed? Or even more modules?

  • πŸ‡©πŸ‡ͺGermany sanduhrs πŸ‡ͺπŸ‡Ί Heidelberg, Germany, Europe

    The "token" is a twig variable and per default available in "Global: Custom text" fields, no further requirements.

  • First commit to issue fork.
  • Assigned to brooke_heaton
  • πŸ‡ΊπŸ‡ΈUnited States brooke_heaton

    We can add a Views Field Handler extending EntityLink to handle this and to render the link as a QR code. I have an initial proof of concept for Nodes that is not customizable but is working.

  • Pipeline finished with Success
    5 months ago
    Total: 239s
    #236157
  • Status changed to Needs review 5 months ago
  • πŸ‡ΊπŸ‡ΈUnited States brooke_heaton
  • πŸ‡©πŸ‡ͺGermany windm

    Hi @brooke_heaton, sorry for the delayed reply here... and thank you for acting on my support/feature request.

    As IΒ΄m not a developer, my stupid question is: "Needs review" means, I could try your Commit 9c441bbc and test it as it is for my case.

    What does it need to get it merged into the regular module 2.0.x or 2.1.x ? Guess, there is an official process for this review and approval? Anything to be done from my side?

  • πŸ‡ΊπŸ‡ΈUnited States brooke_heaton

    @windm - The next step would be to test the patch by applying it via Composer. The patch can be found at teh most recent Pull Request: https://git.drupalcode.org/project/barcodes/-/merge_requests/9.patch

    But, with this change we'd also want a maintainer to take a look at the patch and functionality. It likely needs a Test as well.

Production build 0.71.5 2024