Controlling login/logout in a menu

View: New views
3 Messages — Rating Filter:   Alert me  

Controlling login/logout in a menu

by Jeff Greenberg-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I'm using the secondary menu to put a few links at the top right of the
screen. Among them should be login (if not already) and logout (if
logged in). Adding them to the menu is, of course, not an issue, but how
would I control their appearing or not based on whether the user is
logged in? I was going to use hook_menu_alter, but for some odd reason
it doesn't fire when I'm not on an admin page. Something tells me this
is going to be a forehead slapping moment, it seems so trivial, but it's
eluding me.


Re: Controlling login/logout in a menu

by Dylan Tack :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Oct 21, 2009, at 2:18 PM, Jeff Greenberg wrote:
> I'm using the secondary menu to put a few links at the top right of  
> the screen. Among them should be login (if not already) and logout  
> (if logged in). Adding them to the menu is, of course, not an issue,  
> but how would I control their appearing or not based on whether the  
> user is logged in?

That's automatic if you use the paths "user/login", "logout", and  
"user/register".  (BTW their visibility isn't magical or anything,  
It's controlled by the access callbacks in user_menu()).

-D

Re: Controlling login/logout in a menu

by Jeff Greenberg-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Dylan Wilder-Tack wrote:

> On Oct 21, 2009, at 2:18 PM, Jeff Greenberg wrote:
>> I'm using the secondary menu to put a few links at the top right of
>> the screen. Among them should be login (if not already) and logout
>> (if logged in). Adding them to the menu is, of course, not an issue,
>> but how would I control their appearing or not based on whether the
>> user is logged in?
>
> That's automatic if you use the paths "user/login", "logout", and
> "user/register".  (BTW their visibility isn't magical or anything,
> It's controlled by the access callbacks in user_menu()).
>
> -D
>
>
Thanks! Not quite a forehead slapper, but clearer in hindsight! I did
have logout (but of course, was logged in as admin while doing this) but
had ?q=user instead of user/login. With the zillion lines of code I've
seen in my years, I'm still often humbled by the simplicity that results
from the design, like here. Magical.