It would be spiffy if you could auto-generate QR codes for shurls using the functionality provided by the Mobile Codes module. I am doing this at http://ayl.lv via a hook_form_FORM_ID_alter() in a custom module (go there and create a shurl to see it in action) and a custom Views template file (see screenshot below).

Only local images are allowed.

CommentFileSizeAuthor
#10 Untitled.png10.43 KBLeeHle
#1 qr-codes.jpg71.43 KBjohn bickar
qr-codes.jpg71.43 KBjohn bickar

Comments

john bickar’s picture

StatusFileSize
new71.43 KB

Oops forgot that d.o. doesn't like inline images.

jjeff’s picture

That is soooooo cool!

Do you have any code you can share? What did it take to get this working?

Can you share your hook_form_FORM_ID_alter()?

john bickar’s picture

Well, shurly:


function mymodule_form_shurly_create_form_alter(&$form, &$form_state) {
  if(isset($form_state['values']['short_url'])) {
    $final_url = url($form_state['values']['short_url'], $options = array('absolute' => TRUE));
    $qr_code = theme('mobilecode', $final_url, array('preset' => 'default', 'data' => 'link', 'type' => 'qr', 'size' => 'large', 'tinyurl' => 0));
    unset($form['result']);
    $form['result'] = array(
      '#type' => 'textfield',
      '#size' => 30,
      '#value' => url($form_state['values']['short_url'], $options = array('absolute' => TRUE)),
      '#prefix' => '<div class="shurly-result">',
      '#suffix' => '</div>',
      '#field_prefix' => t('Your short URL: '),
      '#field_suffix' => ' <div id="shurly-copy-container" style="position:relative;"><div id="shurly-copy">' . t('copy') . '</div></div>
      <div><a href="http://twitter.com?status='. url($form_state['values']['short_url'], $options = array('absolute' => TRUE)) .'">' . t('Create a Twitter message with this URL') . '</a></div></div>' . '<div class="qr-code">' .$qr_code. '</div>',
    );
  }
}

And the Views template is views-view-field--shurly-my-urls--source-1.tpl.php (the added View field for QR code is a shurly: short url, output as a full URL with base path, not formatted as a link):

$shurl = $output;
$output = '<div class="qr-code">';
$output .= theme('mobilecode', $shurl, array('preset' => 'default', 'data' => 'link', 'type' => 'qr', 'size' => 'large', 'tinyurl' => 0));
$output .= '</div>';
print $output;

Probably better ways to do it but this was Q&D.

RAINFIRE’s picture

. . . or use the google api.

Add another Global: Custom text and label it QR Codes after the 'Links' and use this example to let google create them. In the Text: box put this:

<div class="shurly-long"><a href="http://chart.apis.google.com/chart?cht=qr&chs=200x200&choe=UTF-8&chld=H&chl=[destination]" target="_blank"> Long QR Code</a></div>
<div class="shurly-short"><a href="http://chart.apis.google.com/chart?cht=qr&chs=200x200&choe=UTF-8&chld=H&chl=[source]" target="_blank"> Short QR Code</a></div>

Working example here: http://ez.vg/

deciphered’s picture

@RAINFIRE,

That approach neither caches it, or will work offline. While Mobile Codes 1.x doesn't work offline, 2.x (currently in development) does provide the ability to use your own offline QR Code generator.

carl.brown’s picture

Massive Kudos to John Bickar for posting that snippet. A big help. Thanks!

jschrab’s picture

For the benefit of others, Drupal 7 theme() calls are slightly different. Here's a simple example of what worked for me:

<?php print theme('mobilecode',array('data' => $output, 'attributes' => array('#preset' => 'small'))); ?>

bserem’s picture

@jschrab could you please tell us where you used this?

thnx

deciphered’s picture

@jschrab,

It's entirely up to you on your personal needs for where you would use that or similar code, put given the fact that he is 'print'ing the code then it's likely that it's in a .tpl.php file somewhere.

LeeHle’s picture

StatusFileSize
new10.43 KB

John Bickar could you help me I'm trying to achieve the exact same thing as in the attachment... I'm a newbie and I'd appreciate step by step help on how to get the same results you have on Drupal 7 though :). So far this is what i have

LeeHle’s picture

@John Bickar could you help me I'm trying to achieve the exact same thing as in the attachment... I'm a newbie and I'd appreciate step by step help on how to get the same results you have on Drupal 7 though :). So far this is what i have

jschrab’s picture

I added a field to the View so that my template override for that column could call theme('mobilecode'...)

1. Add a field to your View to expose the URL 'Short URL' is the field you are looking for and "Output full URL including base path" is the option to check.
2. Look under "Theme->Other->Information" in the View display editor. Look up the tpl filename suggestion of the new field you've added. Create that .tpl file in your theme, then add that theme('mobilecode'...) code into the tpl file. Rescan Template Files.

I'm skimming just details but that's generally it.

LeeHle’s picture

Thank you... let me try that :)

LeeHle’s picture

thank you so much i got it to work @jschrab

jibus’s picture

Component: Code » Documentation
Category: Feature request » Support request
Issue summary: View changes

Since it's possible to achieve this by a custom template, i guess it is not a feature request anymore.

Update the category issue.

jibus’s picture

Status: Active » Closed (won't fix)

Closing issue