I am interested in creating barcodes from field data on-the-fly using the http://drupal.org/project/barcode module. As a rookie, could somebody explain to us how generally this is done and what is the best approach. For my working project example, I've already installed the said module and integrated a field into a Field Collection, but don't really want to spend more hours 'experimenting' to result on nothing. One idea I would like to explore is a QR barcode dynamically appearing on say a user home page (created via Views/Panels). Since my other interests are in music, a working example maybe a link to a band's website (i.e I create a 'Link' field in a Field Collection about a rock band, a visitor views the rock bands 'Homepage' on a D7 site, the link is dynamically shown as a QR code). This example is probably very common and portable across other content sites (trades, places of interest, 'Buy Now' links etc), but a decent 'how to/work through' or generalisation would be most welcome. Again, possibly it is something that can be done in Views or a case of backend PHP in a custom module (in which case I've a lot to learn). Thanks in advance.


It looks like a barcode is just a piece of encoded text from the .module file:

 * Implements hook_field_info().
function barcode_field_info() {
  return array(
    'barcode_field' => array(
      'label' => t('Barcode'),
      'description' => t('This field stores a barcode in the database.'),
      'default_widget' => 'barcode_textfield',
      'enable_tokens' => 1,
      'default_formatter' => 'barcode_default',

So what you likely want to do is creating link fields that upon form submission pass their values onto the barcode field(s) as well. Then, you will show the barcode field(s) on any pages you want and hide the raw link field from the users view (unless their editing the entry).

You could look at the Rules module to automate this for you if you don't want to write a module (for example, when a new piece of content of type Foo, if field link is blah, copy field value to field my_barcode value). Look into the Form API to hide (with #access)the field_barcode values in the edit form (as they are dynamic end-user stuff).

The only thing that the Link field gives you over putting the raw url link in the bar_code field itself is extra form validation for free (for example, check it is a valid URL).


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.