0

I want to add edit account menu item in user menu, I want the URL to be user/{user_id}/edit. How can I achieve this without menu_token module. I also tried creating menu item programatically as follow

$items = array();
  global $user;
  $user_id = $user->uid;
  $items['user/' . $user_id . '/edit'] = array(
    'title' => 'Edit account',
    'access callback' => 'user_is_anonymous',
    'menu_name' => 'user-menu',
    'type' => MENU_SUGGESTED_ITEM,
  );

  return $items;

But newly created menu item only shows at back-end i.e. at structure/menu/user-menu but it doesn't display it on front-end.

1
function hook_menu() {
  $items = array();
  global $user;
  $user_id = $user->uid;
  $items['user/' . $user_id . '/edit'] = array(
    'title' => 'Edit account',
    'page callback' => 'MYMODULE_user_edit',
    'access callback' => 'MYMODULE_user_edit_access',
    'menu_name' => 'user-menu',
    'type' => MENU_SUGGESTED_ITEM,
    'file' => 'user.pages.inc',
    'file path' => 'modules/user'
  );

  return $items;
}

function MYMODULE_user_edit() {
  global $user;
  $account = user_load($user->uid);
  return drupal_get_form('user_profile_form', $account);
}

function MYMODULE_user_edit_access(){
  global $user;
  return user_edit_access($user);
}

Try above code. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.