Currently my users are being redirected to a node after trying to first access that node's comment page (comment/reply/nid) via a link in a view. This is because I've set it so you have to be logged in to leave a comment. In the message area, on the node that they are redirected to, is an error message, "Error message: You are not authorized to post comments."

I want to change this so that when an anonymous user accesses the comment/reply/nid she is presented with a login page and then directed back to the comment/reply/nid.

I've tried logintoboggin, but that doesn't seem to work. This is possibly because an access denied message is being displayed, not a 403.

I have a view that displays links to comment on various nodes, and I tried altering the links in this view via hook_views_pre_render. I was going to try and add a modal window containing a login form if the user was anonymous by taking a more html and js approach a la Twitter Bootstrap. But I was unable to locate the link in the massive view array. I was hoping for a render array to modify (add a class, add an attribute, etc). Not even sure if this would be a "Drupal kosher" approach.

Any ideas?

  • Are you using drupal 7 or drupal 6? If 6, are you using views 2 or 3?
    – rooby
    Commented Feb 2, 2013 at 2:03
  • d 7.19, views 3.5.
    – cdmo
    Commented Feb 2, 2013 at 2:08
  • Are your links to comments a views field?
    – rooby
    Commented Feb 2, 2013 at 2:17
  • yes, a title field where I've re-written the link output to comment/reply/[nid]
    – cdmo
    Commented Feb 2, 2013 at 2:20

1 Answer 1


You can do it in hook_views_pre_render() like this:

 * Implements hook_views_pre_render().
function MODULENAME_views_pre_render(&$view) {
  if ($view->name == 'VIEWNAME') {
    if (!user_is_logged_in() && !empty($view->field['FIELDNAME']->options['alter']['path'])) {
      $view->field['FIELDNAME']->options['alter']['path'] = 'user/login?destination=' . $view->field['FIELDNAME']->options['alter']['path'];

Where in this case I would say 'title' is your FIELDNAME.

This will, if the user is logged out, replace whatever you have for your link in the rewrite settings, with a link to the login page, with your original path as the query destination, which will be used to return you to that page after the login form is submitted.

Also, there is the modal_forms module, which might be worth trying for a pop-up solution. However then you need to take them to the comment reply page after the modal form closes.

  • yep, that definitely did it. thanks! I knew it had to be somewhere in that array :)
    – cdmo
    Commented Feb 2, 2013 at 4:29

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.