1

I want to to use login_destination module to have a link to login screen in comment-wrapper.tpl.php, so after the login, the user came back to write the comment.

I have installed and configured login_destination and modified comment-wrapper.tpl.php.

The login_destination documentation say that if I use my own links to the login screen, i have to use GET to supply "current" parameter.

So in my theme I've added to comment-wrapper.tpl.php:

$destino = drupal_get_destination();
$destino = $destino['destination'];

And changed the text to add the link to the login screen:

<?php if ($comment_form): ?>
<h2 class="title comment-form"><?php print t('<a href="@login">Login</a> or anonymous comment:', array('@login' => url('user', array('query' => array('current' => $destino), 'fragment' => 'comments')))) ?></h2>
<?php print $comment_form; ?>

Now, when I click on "Login" link, opens an url like:

SITE.com/user?current=node/3#comments

But after finish the login, I'm redirected to node/3 alias, without the anchor #comments.

If I type on the browser the url:

SITE.com/node/3#comments

It' works ok, it goes to the #comments anchor.

Any help or suggerence?

Thanks!

0

Try this.

<?php if ($comment_form): ?>
        <h2 class="title comment-form"><?php l('Login or anonymous comment', user, array('query' => 'current=node/3#comments')); ?></h2>
<?php print $comment_form; ?>
  • I've tried with: <h2 class="title comment-form"><?php print l(t('login or anonymous comment'),'user', array('query' => 'current=node/3#comments')); ?></h2> But it gives me an error: Recoverable fatal error: Argument 1 passed to drupal_http_build_query() must be an array, string given, called in /var... I think its because your code is for drupal 6 and I'm with drupal 7. I have tried these: <h2 class="title comment-form"><?php print l(t('login'),'user', array('attributes' => array('query' => array('current' => 'node/3#comments')))); ?></h2> but then the link just points to: 'user' :-? – linux with a hammer Jun 28 '12 at 21:52
  • Try your code like this <h2 class="title comment-form"><?php print l(t('login'),'user', array('attributes' => array('query' => 'current=node/3#comments'))); ?></h2> – aerozeppelin Jun 29 '12 at 13:35
  • I've tried, but with this code the link in "user" points just to SITE.COM/user. Without the anchor and the query... – linux with a hammer Jun 29 '12 at 16:19
0

Update: after reading your quesiton again, it seems that redirecting to a fragment is not possible with destination or current parameters. See this Here is my previous answer where I assumed the problem was in the l() function.

Just have a look at

<?php if ($comment_form): ?>
<h2 class="title comment-form">
<?php print t('!login or anonymous comment:', 
        array('!login' => l(t('Login'), 'user/login', array(
          'query' => array('current' => $destino), 
          'fragment' => 'comments')))); ?></h2>
<?php print $comment_form; ?>

A few points: I have used !login in the t() function. if you use @login, it will not be parsed as HTML. Instead, you will see the a tag in plain text.

l() function accepts the actual text of the A tag. We need to use t() function here.

I just tested it myself and worked for me.

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.