Reputation: 176
How can I add a new tab to user profile. I want to add for instance New User Tab which will be visible by administrator and user itself (not others).
Upvotes: 1
Views: 2215
Reputation: 176
Hi friends thanks for helping me.... I done with under code
function downloaded_menu(){
$items['user/%user/downloaded'] = array(
'title' => 'Downloaded',
'page callback' => 'downloaded_content_page',
'access arguments' => array('access content'),
'type' => MENU_LOCAL_TASK,
'weight' => 10,
);
return $items;
}
Upvotes: 1
Reputation: 68
You can achieve this through the views module without having to do custom coding.
Set up a new view page with path as 'user/%' Set contextual filter as 'user:uid'
Set your page content as 'user' or 'fields' or whatever you want rendered. This is going to 'hijack' the standard drupal page into a views rendering.
Now you can add any amount of additional tabs by adding views pages and setting the path to 'user/%/path_of_your_tab'. Set the menu entry for each tab to 'menu tab' and 'user menu'
You can then set access permissions in views for each tab.
Upvotes: 1
Reputation: 9
If you want to create your own module, the code will look like this:
<?php
// Define callback for tab.
function user_tab_menu(){
return array(
'user/%/new_tab' => array(
'title' => 'New tab',
'page callback' => 'user_tab_page',
'page arguments' => array(1),
'access callback' => 'user_tab_access',
'access arguments' => array(1),
'type' => MENU_LOCAL_TASK,
),
);
}
// Show the page
function user_tab_page($uid){
return 'New tab';
}
// Check if user has permission, or views its own page
function user_tab_access($uid){
return ($uid == $GLOBALS['user']->uid) || user_access('view user tabs');
}
// Define permission for administrators
function user_tab_perm(){
return array(
'view user tabs' => array(
'title' => t('View user tabs'),
'description' => t('View user tabs'),
),
);
}
Upvotes: 1