HOWTO: Smart Login Menu Hook
Navigation : Back to Blog
It is a neat property of Drupal that you can define a menu item pointing at "logout" that, because of its permissioning, only shows up to users who are logged-in (and in need of logging-out). This same trick, sadly, does not work for login because "user/login" is accessible to both logged-out users (as the login page) and to logged-in users (as their profile page) - so it shows up all the time which can be sort of confusing.
One solution is to employ the following menu hook to create the location "login". Then you can set up two menu items (Login pointing to "login", Logout pointing to "logout") which will smartly switch placement depending on the logged-in/logged-out status of the user. Just throw the following code in a module and away you go:
function smartlogin_menu($may_cache) {<br /> $items = array();<br /> global $user;<br /> if ($may_cache) {<br /> $items[] = array(<br /> 'path' => 'login',<br /> 'title' => t('Login'),<br /> 'callback' => 'drupal_goto',<br /> 'callback arguments' => array('user/login'),<br /> 'access' => ($user->uid == 0),<br /> 'type' => MENU_CALLBACK);<br /> }<br /> return $items;<br />}Comments
Post a comment
Presentations
What we've coded
Videos
Upcoming workshops
-
San Francisco, CAFebruary 28, 2012
-
Denver, COMarch 19, 2012








it adresses a good point, I wonder it would be good idea to submit to logintobpggan.module at Drupal
regards
we fixed this in drupal 5 ... still a good tip
Hi, thanks for sharing this. Just one silly question; how does the smartlogin_menu ever get called? As my first foray into menu hooks, putting this into my module did, well, nothing! :)
This assumes you're using a module called smartlogin.module. The hook_menu command is one of drupal's core means for including functionality. Whatever your custom module is called, modulename_menu will fire when drupal is building its menu system, so you'll need to name the function accordingly.
More information here:
http://api.drupal.org/api/4.7/function/hook_menu
And how would this be done in drupal 6 is something I'd like to know...
Pretty nice place you've got here. Thanx for it. I like such themes and anything that is connected to them. I would like to read more soon.
Anete Benedict
newry escorts