User Menu Tab on the Drupal User Profile Page

I want to add a menu item next to the menu links [view] [edit] [files] ... at the top of the user profile page. When a user clicks on him, he should behave like the others, since he does not just launch on a new page, but the menu item that they clicked on (let him call it โ€œFunky Buttonโ€) turns gray and the user remains in the user's profile area.

I created a hook as shown below:

function my_module_funky() { // TODO: what to do? } function my_module_menu() { $items['user/%user/funky'] = array( 'title' => t('Funky Button'), 'page callback' => 'my_module_funky', 'page arguments' => array(1), 'access callback' => TRUE, 'access arguments' => array('access funky button'), 'type' => MENU_LOCAL_TASK, ); return $items; } 

So this piece of code adds a button - but I can't figure out how to make it appear, since the view and edit buttons display their contents. Thanks!

+3
source share
1 answer

Your callback should return a string containing the HTML code of the page to display, for example:

 function my_module_funky($user){ drupal_set_title('Funky page'); return 'This is the $user value: <pre>'.var_export($user, true).'</pre>'; } 

$user comes from the string 'page arguments' => array(1) your hook_menu , which passes the value of the %user wildcard as the first callback argument to your page.


If this is a complex page, you may need to create a theme function with a template file, so you can save the page code in a .tpl.php file, which will simplify its work (especially if your module creates many such user pages).

It would also allow those themes to customize the page output by providing their own version of the .tpl.php file if your module becomes popular, or other modules can pre-process the page to add / change variables.

0
source

All Articles