0

I need to be able to click on a link, that goes to node/add/example. and populate a term reference field with a URL parameter. I thought i could be able to do this through the default value, but i guess it isn't possible. Anyone have any other ideas to try?

0

For drupal 6:You can put a link using following code in your node.

function hook_link($type, $object, $teaser = FALSE) {
  $link = array();

  if ($type == 'node') {
    $link['yourlinkname'] = array(
      'title' => t('Your link'),
      'href' => 'node/add/example',
      'attributes' => array(
        'title' => 'Your link',
      ),
    );
  }
  return $link;
}

For drupal 7:You can put a link using following code in your node.

function hook_node_view_alter(&$build)
{
   $build['links']['node']['#links']['example-mylink'] = array(
    'title' => t('Your linkname'), 
    'href' => 'node/add/example', 
    'html' => TRUE, 
    'attributes' => array(
      'title' => 'Your link',
      ),
   );
}
2
  • Thank you for your answer. I will give it a shot and get back to you. May 5 '15 at 19:52
  • Ya sure. anytime. I am waiting for your reply.
    – Viraj
    May 6 '15 at 5:57
0

If you want to avoid custom code, two modules exists for this task:

  • Entityreference prepopulate: this is IMHO the best solution for your case. When prepopulating you can hide the field or disable it, and you can define what to do if the argument is not passed (do nothing, hide field, set a form error or redirect the user).
  • Prepopulate: more "basic" module, it simply fills the forms field with the argument that you put in the 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.