0

I am using the ShURLy module to create short links for nodes. I would like to be able to create the short links when nodes are published, automatically, without having to do the extra steps of clicking on the Bookmarklet which opens a new page where I create the short link by clicking on a button/link.

How can I achieve this?

update

I am using workbench so I added

function my_node_workbench_moderation_transition($node, 
$previous_state, $new_state) {
// Generate the short link when it is published.
  if ($new_state == 'published' && $previous_state != $new_state) {
    $link = my_node_create_short_link($node->nid); 
  }
}    

and the function my_node_create_short_link with shorten (shorten_url)

function my_node_create_short_link($node_id) {
 // Do not create the short link if already exists.
  $link = my_node_short_link_get($node_id);
  if ($link) {
      return $link;
  }
  else {
    $link = shorten_url(url('node/' . $node->nid, array('absolute' => TRUE)));
    // Insert the link
    my_node_short_link_insert($node->nid;, $link);
    cache_set($node->nid;, $link);
    return $link;
  }

}

1 Answer 1

1

As per the current module functionalities it does not seem to have that feature. So I think you need to create custom module.

In your custom module you will require to use hook_node_insert (For Drupal 7) this hook to execute after each node is added. Then Shurly provides API to create short link, using those APIs you can create short link as an when required.

Hope this helps.. :)

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.