9

I'm using the Flag module, but I have a problem in displaying a flag to anonymous users.

I have 2 flags called "make feature" and "add to Favorites". I want to display this flag to anonymous users too. Currently it is displayed only to the users who are logged in (authenticated user).

I want these flags to be displayed to all users (whether logged in or not). But when an anonymous user clicks on flag than such user should be redirected to the login page. After login the user should be able to set flag.

Is this possible?

  • What's a flag in your context? A menu entry? – BetaRide Jun 29 '12 at 5:57
  • @BetaRide : I think OP is talking about flags by Flag module – AjitS Jun 29 '12 at 6:01
  • yes i am using flag module. – Pranav Gandhi Jun 29 '12 at 6:08
10

You can do this in your 'node.tpl.php' by something like below, if user is logged in display flag as normal and if is not logged in redirect user to logging page with destination parameter

global $user;
if(!$user->uid) {
    // $flag: bookmark or make_feature, $action: flag, $content_id: $nid.....
    $flag_link = flag_flag_link($flag, $action, $content_id);
    $flag_url = $flag_link['href'];
    if(isset($flag_link['query']['token'])) {
        $flag_url .= '?'.$flag_link['query']['token'];
    }
    print l(t('bookmark'), 'user/login' , array('query'=> array('destination' => $flag_url)));
} else {
    print render($content['links']['flag']);
}
4

To display a flag to anonymous users, refer to what's written in the community documentation of the Flag module, i.e.:

Flagging for anonymous users (even with page caching enabled). Requires Session API.

Something similar from the README.txt:

Optional Installation

1) The ability for anonymous users to flag content is provided by the Session API module, available at http://drupal.org/project/session_api.

Be aware also that Session API isn't mentioned as a dependency in the Flag module either.

1

https://www.drupal.org/project/flag_anon

Offer an option to display of "sign in or register" for a flag for anonymous users.

protected by kiamlaluno Sep 18 '12 at 0:32

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.