Menu item uid
Categories
Component ID
2698969
Component name
Menu item uid
Component type
module
Maintenance status
Development status
Component security advisory coverage
not-covered
Component created
Component changed
Component body
Summary
Experimental module for developers to make possible to add menu links with a placeholder of current user uid.
I.e. it's possible to put into menu the link like user/%uid/edit
Usage
To make this work you need to make next things:
1. Implement hook_menu_item_uid_items() in your module.
I.e.
function YOUR_MODULE_menu_item_uid_items() {
return [
'user/%user/edit' => '%user',
];
}
2. You need to implement 2 tiny extra functions to (if they don't yet done yet. For now 2 types supported: %user and %profile2_by_uid menu callback placeholders):
function menu_item_uid_path_user_load($uid, $reset = FALSE) {
return user_load($uid, $reset);
}
function menu_item_uid_path_user_to_arg($arg) {
return empty($arg) || $arg == '%menu_item_uid_path_user' ? $GLOBALS['user']->uid : $arg;
}
3. Previous step make possible to create menu links to user edit page with placeholder:
'user/%menu_item_uid_path_user/edit'
Another example
function YOUR_MODULE_menu_item_uid_items() {
return [
'profile-moderator/%profile2_by_uid/edit' => '%profile2_by_uid',
];
}
function menu_item_uid_path_profile2_by_uid_load($uid, $type_name) {
return profile2_by_uid_load($uid, $type_name);
}
function menu_item_uid_path_profile2_by_uid_to_arg($arg) {
return empty($arg) || $arg == '%menu_item_uid_path_profile2_by_uid' ? $GLOBALS['user']->uid : $arg;
}
After this you could create menu links to profile2 edit page, i.e. 'profile-moderator/%menu_item_uid_path_profile2_by_uid/edit'
Other modules
- Menu token — more complicated and supports any type of tokens. But it requires UUID module for proper export and create dummy menu items which is not ok for my case (menutoken/xxxx).
- Me — works via redirect which is also not always desired.
