2

I wish to create automatically created barcodes from newly create Node content and also Node content already created in the Drupal V7.3x system. Further to my previous posting Barcode Creation I can allow a user to create a QR barcode from a text field entered on a Node Form which successfully shows the QR on the Node display page; but this is no longer what I want, I require the QR code to create on the fly to create the QR code which will ultimately be the URL of that Node which is being shown so that the user then can scan it and save for later ie on a mobile device.
I have tried with Rules, but to date cannot get the Rule to write, save or show any QR code.

If it is a PHP script code, then what would it be to create onto the Node page the user would see.

I want to do it via Rules is possible but the barcode field wasn't showing in Rules. Any advice on a correct procedure or a Rules structure is most welcome.

PS:

I have found this type of PHP on https://www.drupal.org/node/1364118, and I wonder if this is the direction I need to go? to solve it:

    <?php
if (!isset($commerce_product->field_barcode['und'][0]['value'])) {
$commerce_product->field_barcode['und'] = array(0 => array ('value' => $commerce_product->sku)); 
}
else {
if ($commerce_product->field_barcode['und'][0]['value'] == '') {
$commerce_product->field_barcode['und'][0]['value'] = $commerce_product->sku;
}
}
commerce_product_save($commerce_product);
?>

3 Answers 3

1

Since my original posting, a new module appeared. So I ultimately chose this module: drupal.org/project/page_url_qr_code_block does the job spot on and creates Node QR Codes on the fly via a Block. There maybe other ways, but for now, this is it. Thanks all.

0

The Ugly way: print qr-related to node on node template in your theme.

Less restrictive way: Create extra field in a module. hook_field_extra_fields Google offers good examples with decent snippets with that hook search.

4
  • I want to do it via Rules is possible but the barcode field wasn't showing in Rules. I found this article: drupal.org/node/1608378 which suggest the barcode Field can be added by adding to "Implements hook_field_info().". I have done this and now the Barcode field is available. I'll keep readers posted, in the meantime any comments are most welcome to my approach.
    – Paul B
    Commented Feb 18, 2015 at 15:29
  • I've got minimal exp with rules and never installed barcode module, but im posting this anyway in case your going to look norules options. barcode_theme seems to tell it can be exploited directly. print theme('barcode_image', array('barcode_value'=>'http://...', ...etc));
    – user20301
    Commented Feb 18, 2015 at 16:24
  • Again, thanks @user20301 for your comments, much appreciated (-:
    – Paul B
    Commented Feb 18, 2015 at 16:59
  • A work around I think can achieve what I want is to create a View and then have some PHP print the field data as the QR code, I wonder if this is achievable and a better alternative?
    – Paul B
    Commented Feb 19, 2015 at 11:51
0

Below is a possible explanation/solution to this part of your question:

I want to do it via Rules is possible but the barcode field wasn't showing in Rules.

This is a typical "issue" (not problem or bug) with the Rules module.

Make sure to add a Rules condition Entity has field (related to your barcode field) in your Rules condition). And make sure to add that Entity has field condition BEFORE other condition(s) you may already have.

That's also what is mentioned in the Rules UI when you're adding a "data comparison" condition: somewhere it says "The data selector helps you drill down into the data available to Rules. To make entity fields appear in the data selector, you may have to use the condition 'entity has field' (or 'content is of type')".

Refer to my answer to "How to specify a Rules condition related to select list values?" for an actual Rules example (in Rules export format) that includes such 'entity has field' condition.

For a video tutorial that illustrates the importance of this Entity has field condition, refer to Data types and data selection, especially what is shown between about 13:30 and 17:30 in it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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