0

I'm running Advanced Forums on D7, and when an anonymous user views a forum post (lets say nid 101) there is link under the post that says "Log in or register to post comments".

The problem is it is supposed to point to 'user/login?destination=node/101#comment-form' but the url encoding causes it to become 'user/login?destination=node/101%23comment-form'

I looked inside core's comment module, under function theme_comment_post_forbidden line 2387 says:

$destination = array('destination' => "node/$node->nid#comment-form");
return t('<a href="@login">Log in</a> or <a href="@register">register</a> to post comments', array('@login' => url('user/login', array('query' => $destination)), '@register' => url('user/register', array('query' => $destination))));

but I think it should make the #comment-form a url fragment:

$destination = array('destination' => "node/$node->nid");
$fragment = 'comment-form';
return t('<a href="@login">Log in</a> or <a href="@register">register</a> to post comments', array('@login' => url('user/login', array('query' => $destination, 'fragment' => $fragment)), '@register' => url('user/register', array('query' => $destination, 'fragment' => $fragment))));

How I can create a hook to this and change the link?

  • In that case, #comment-form would apply to user/login, not to node/101. A fragment is applied to the current page, not a URL parameter. – kiamlaluno Dec 29 '15 at 6:41
  • @kiamlaluno thanks, I've edited my post to include the link output code from comment.module. Hope that clarifies? – longboardnode Dec 29 '15 at 12:58
0

I found the solution with the help of this SE post. Using MYMODULE_node_view_alter(&$build) and MYMODULE_comment_view_alter(&$build) in my custom module, I was able to change the values using:

$build['links']['comment']['#links']['comment_forbidden'] = str_replace('%23','#', $build['links']['comment']['#links']['comment_forbidden']);

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.