2

According to a comment on Drupal's AJAX framework it should be possible to define a link as a render array which Drupal then would turn into an ajaxified link. As far as I understand it, the essential part of this is :

$link = array(
  '#type' => 'link',
  '#title' => t('something'),
  '#href' => 'some/path',
  '#ajax' => array(
    'callback' => 'some_callback_function',
    'wrapper' => 'ajax-response-goes-here',
    'method' => 'replace',
    'effect' => 'fade',
  ),

However, I'm not quite certain which url the client would use to actually invoke the AJAX request? I know forms use 'system/ajax' to access callback methods from there, but what about this case?

If anyone would have the chance to shed a little light on how to properly ajaxify links, I'd be very greatful!

  • 2
    Have a look at the Examples module; it has an ajax_example module that walks you through how to do this. There's an extensive explanation and code examples in the ajax_example_misc.inc file – Clive Jun 21 '12 at 17:56
  • @Clive, thanks for disappeared but awesome link to slideshare.net/merlinofchaos/drupal-7-advanced-ajax – kalabro Jun 21 '12 at 17:58
  • 1
    @kalabro Wow you're quick that was only there for about 20 seconds! I thought the examples module link was a bit more appropriate as it's got a great example for what the OP is after. It is an awesome slideshow though, glad I came across it – Clive Jun 21 '12 at 18:00
2

I would be rather suspicious about the '#ajax' way. Try to have a look here : http://api.drupal.org/api/examples/ajax_example%21ajax_example_misc.inc/function/ajax_example_render_link/7

What they say :

  • include the ajax.js
  • add use-ajax class
  • implement ajax callback under the link your link directs to

what should be done after the callback executes can be set by the ajax commands.

  • 1
    But the very next function in the file (ajax_example_render_link_ra()) shows how to do it with a render array. ;) – Clive Jun 21 '12 at 18:01
  • I used same but it didn't work for me. :( Any solution? – Sumit Madan Dec 12 '12 at 10:23

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.