Is there a way of creating an QR/Datamatrix code on the fly for each node pointing to its own URL?

I find your module very interesting but I find no way to creat the codes dynamically for each node. Maybe some examples in your documentation could help...

Thanks anyway!

psc

Comments

mwhalen’s picture

I think most people would love this too!

szantog’s picture

Ok, I made it.
Download the module computed_field.
Enable it, then make a computed field cck field.
On field settings page use this code in computed code field:

  if (module_exists('mobile_codes')) {
    global $base_url ;
    $data = $base_url . '/' . drupal_get_path_alias('node/' . $node->nid) ;
    $tinyurl = drupal_http_request('http://tinyurl.com/api-create.php?url='. urlencode($data), $headers, 'POST', NULL);
    if ($tinyurl->code == 200) {
      $data = $tinyurl->data;
    }
    return $node_field[0]['value'] = theme_mobilecode($data);
  }
  $node_field[0]['value'] = 'This field needs <a href="http://drupal.org/project/mobile_codes">mobile_codes</a> module' ;

On Display Fields page set the field display mode "Computed Value".

hixster’s picture

hey szantog, many thanks for this solution - can you give any pointers for the other computed field settings that might be necessary - I can't seem to get this to work??

Got it working after removing the php tags

skizzo’s picture

Another option: as I was already using the Rules module, I added a couple of rules
- trigger: on save/update content
- condition: for specific Content Type
- action: populate 'field_mobile_code' with token [node:node-url]

deciphered’s picture

Status: Active » Fixed

There are plenty of other ways to achieve this result, I personally would create a block to do it... which is exactly what I have done in 6.x-2.x.

Enjoy.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

itivet’s picture

I can't find out how to set rules "- action: populate 'field_mobile_code' with token [node:node-url]"
can anyone help me? thx a lot.

skizzo’s picture

on your rule you should click on "Add an action" and select the action "Populate a field" (from CCK list ). Pick "created content" as argument and select the machine name of the field you want to populate (I use a text field added for that purpose), then enter something like http://www.yoursite.com/node/[node:nid]

skolesnyk’s picture

Skizzo, not sure I understand why CCK field is of text type? Should that be file type so that generated QR code is saved as a file?

I'm profoundly confused: and where's invocation of Mobile Codes to generate the actual code? I did what you suggested and, obviously, the field is populated with node id. I just don't get.

skizzo’s picture

Ok, the field is populated with the node URL (http://www.yoursite.com/node/nid). Now, the Mobile Codes module "provides the ability to render Text, URLs or any other form of informaton as a Mobile Code", so you only need to pick the right formatter in the CCK field display configuration, and Mobile Codes will render it for you. Note that using the provided Node URL block would be a more efficient way of doing it.

skolesnyk’s picture

Thanks! Yes, Node URL block generates QR code just fine, but I'd love that extra flexibility of having QR code as a file.

Buckminster_Bond’s picture

skolesnyk - this may help you - it's a link to another issue on the queue where the filepath of the code is output via custom formatters/views...

http://drupal.org/node/1135594

mattbk’s picture

I couldn't get #2 to work in D7, even after changing $node_field to $entity_field, so I'm assuming something else would need to be changed and could use some help.

I'm using #4 as a workaround right now*, but this method requires the node to be edited before the field will populate, which obviously means a lot of work for existing nodes. Thanks for the help, though!

*In D7 Rules i works out to "Set a data value--Parameter: Data: [node:field-mobile-code], Value: [node:url]" for the third step.

socialnicheguru’s picture

could I use custom_formatters to create this just for the Content:Link in a view?