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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

beginner’s picture

Version: 4.7.2 » x.y.z
Status: Needs review » Needs work

+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

Darren Oh’s picture

I tried adding the code to the user module, but it didn't work.

beginner’s picture

the code is designed like an independent contrib module.
Just keep the active part:

    $items[] = array(
      'path'      =>  'login',
      'title'    =>  t('log in'),
      'access'    =>  !($user->uid),
      'callback'  =>  'drupal_goto',
      'callback arguments' => array('user/login', drupal_get_destination()),
      'weight'    =>  -10,
      'type' => MENU_DYNAMIC_ITEM | MENU_NORMAL_ITEM,
    );

to be added, I guess, in user_menu().

Darren Oh’s picture

Status: Needs work » Reviewed & tested by the community
FileSize
771 bytes

I must have had some typos in the code. This patch works fine.

drumm’s picture

Status: Reviewed & tested by the community » Needs work

- 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.

Darren Oh’s picture

Status: Needs work » Reviewed & tested by the community
FileSize
628 bytes

I 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.

drumm’s picture

Status: Reviewed & tested by the community » Needs review

I 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.

Darren Oh’s picture

I 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.

rwohleb’s picture

Version: x.y.z » 4.7.0

As this issue is not going anywhere, I've created a project to house the module referenced.

http://drupal.org/project/loginmenu

Darren Oh’s picture

Thank 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.

anders.fajerson’s picture

Version: 4.7.0 » 5.x-dev
greggles’s picture

Version: 5.x-dev » 6.x-dev

As 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.

Darren Oh’s picture

Title: Add Log-in to Navigation Menu » Provide log-in item for navigation menu
keith.smith’s picture

Status: Needs review » Needs work

patch 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]#

deekayen’s picture

subscribing

Pancho’s picture

Version: 6.x-dev » 7.x-dev
Priority: Minor » Normal

Too late for D6. Moving to the D7 queue.

deekayen’s picture

Title: Provide log-in item for navigation menu » Provide suggested log-in item for navigation menu
FileSize
605 bytes

Here'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.

olamaekle’s picture

Version: 7.x-dev » 8.x-dev

So... Any work on this?

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

dpi’s picture

Issue summary: View changes
Status: Needs work » Closed (won't fix)

We already have this feature.

User account menu has a dual use menu item: Log out ("Log in" for anonymous users)