Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
If you're using the flag_create_link() function, you'll notice that if the particular flag's settings do not allow the user to use the flag, then no markup at all is returned.
To get around this, I think you'd have to give anon users the permission to use the flag, and then create your own theme's implementation of flag.tpl.php which checks for the anon user and simply sets the flag link to go to /user/login.
------------------------------------------ EDIT:
On second thought, for the sake of (a) avoiding using a false permission setting as a workaround, and (b) moving the logic to run earlier, I realized it would be better to check whether the user is logged in and then either print a placeholder link to log in or run flag_create_link(). E.g.:
global $user;
if($user->uid > 0) {
print flag_create_link('favorites', $node->nid);
}
else print l("Log in to favorite", "user/login");
Comments
Comment #1
tea.time CreditAttribution: tea.time commentedI'm in a similar situation...
If you're using the
flag_create_link()
function, you'll notice that if the particular flag's settings do not allow the user to use the flag, then no markup at all is returned.To get around this, I think you'd have to give anon users the permission to use the flag, and then create your own theme's implementation of flag.tpl.php which checks for the anon user and simply sets the flag link to go to /user/login.
------------------------------------------
EDIT:
On second thought, for the sake of (a) avoiding using a false permission setting as a workaround, and (b) moving the logic to run earlier, I realized it would be better to check whether the user is logged in and then either print a placeholder link to log in or run flag_create_link(). E.g.:
Comment #2
joachim CreditAttribution: joachim commentedClosing support requests older than a year. Feel free to reopen if this is still relevant.