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.
This issue was brought up in forum post 14223. Someone provided instructions for creating a module to add log-in to the navigation menu. It seems more appropriate to add this function to the core user module.
The code for the function is this:
function loginmenu_menu($may_cache) {
global $user;
$destination = drupal_get_destination();
$items = array();
if($may_cache){
$items[] = array(
'path' => 'login',
'title' => t('log in'),
'access' => !($user->uid),
'callback' => 'drupal_goto',
'callback arguments' => array('user/login', $destination),
'weight' => -10,
'type' => MENU_DYNAMIC_ITEM | MENU_NORMAL_ITEM,
);
}
return $items;
}
I'm also attaching a copy of the module.
Comment | File | Size | Author |
---|---|---|---|
#17 | 74706_login_suggested_menu.patch | 605 bytes | deekayen |
#6 | user.module.login-link_0.patch | 628 bytes | Darren Oh |
#4 | user.module.login-link.patch | 771 bytes | Darren Oh |
loginmenu.module | 1.11 KB | Darren Oh |
Comments
Comment #1
beginner CreditAttribution: beginner commented+1 on the idea. This way, the login link can even be added in the primary/secondary links, if wanted.
please provide a patch against cvs.
http://drupal.org/patch
Comment #2
Darren OhI tried adding the code to the user module, but it didn't work.
Comment #3
beginner CreditAttribution: beginner commentedthe code is designed like an independent contrib module.
Just keep the active part:
to be added, I guess, in user_menu().
Comment #4
Darren OhI must have had some typos in the code. This patch works fine.
Comment #5
drumm- This should be a MENU_SUGGESTED_ITEM so it is hidden by default and can be easily enabled via the menu administration.
- This should change the existing menu item instead of creating a different one that only redirects.
Comment #6
Darren OhI modified the patch to make login a suggested menu item. It's not possible to modify the user/login item because it works differently from the login item. user/login redirects to the users account if the user is logged in; login is not accessible to users who are logged in.
I put the code for the login menu together with the code for the logout menu to make its function clearer.
Comment #7
drummI still don't like the idea of adding a duplicate menu item for this.
Please do not mark your own issues as ready to commit, this needs someone to review it.
Comment #8
Darren OhI don't understand why this would be a duplicate menu item. The existing user login uses the menu system but does not provide a menu item. It requires a block. It seems consistent that if logout is a menu item, there should be an option to make login a menu item also. If someone redesigns the existing login to show up in the menu I will be glad to close this issue. At the moment my programming skills aren't up to it.
Comment #9
rwohlebAs this issue is not going anywhere, I've created a project to house the module referenced.
http://drupal.org/project/loginmenu
Comment #10
Darren OhThank you. I hope this gets in core soon. I don't know why this has been made such a big issue that we have to have a separate project for it.
Comment #11
anders.fajerson CreditAttribution: anders.fajerson commentedComment #12
gregglesAs long as this is considered a feature this is unlikely to get it until 6.
I suggest campaigning for it on Development list if you think it's a good idea.
Comment #13
Darren OhComment #14
keith.smith CreditAttribution: keith.smith commentedpatch no longer applies
# patch -p0 < user.module.login-link_0.patch
patching file modules/user/user.module
Hunk #1 FAILED at 741.
1 out of 1 hunk FAILED -- saving rejects to file modules/user/user.module.rej
[root@h99846 test]#
Comment #15
deekayen CreditAttribution: deekayen commentedsubscribing
Comment #16
PanchoToo late for D6. Moving to the D7 queue.
Comment #17
deekayen CreditAttribution: deekayen commentedHere's an updated patch. The problem with this patch is that combining a suggested item with a local task appears to make the suggested one normal (and active), because the local task part is active. That means if you apply this patch and view Drupal while logged out, you'll get both a Log in link and a login form block. The original patch was able to abuse having two different array options, but I think this should figure a way to use the same one.
Comment #18
olamaekle CreditAttribution: olamaekle commentedSo... Any work on this?
Comment #21
dpiWe already have this feature.
User account menu has a dual use menu item: Log out ("Log in" for anonymous users)