Hi folks,

My first attempt at a hook_menu() module results in WSOD

<?php
* Implementation of hook_menu().
* Adds a menu tab to the User menu.
*/

function menutweaks_menu() {
$items = array();
  $items['users/%user'] = array(
    'title' => 'USE REG KEY',
    'page callback' => 'og/reg-key-join',
    'page arguments' => array(1),
    'access callback' => TRUE,
    'type' => MENU_LOCAL_TASK,
  );

  return $items;
}

I am trying to add a menu tab to my user pages, save my blushes please folk!

Comments

Page callback

The page callback should be a function name that will display the webpage. That does not appear to be a valid function name.

Have a look at hook_menu at Drupal API:

http://api.drupal.org/api/drupal/developer%21hooks%21core.php/function/h...

Make sure to do a cache clear whenever you are using hook_menu and make a change.

~Chad

~Chad

Thanks for the info Chad, Ok,

Thanks for the info Chad,

Ok, so what about:

'page callback' => 'drupal_get_form',
   

thanks for the tip "clear the caches"

The page I want to display is here "page arguments' => array('og_reg_keys_join'),"

Please excuse my ignorance of module development, we all got to start somewhere..

If you wanted to duplicate

If you wanted to duplicate the page displayed at og/reg-key-join in a tab, you need to duplicate its page callback/page arguments.

From http://drupalcode.org/project/og_reg_keys.git/blob/refs/heads/6.x-1.x:/o...

    'page callback' => 'drupal_get_form',
    'page arguments' => array('og_reg_keys_join'),

Be gentle guys.. pretty

Be gentle guys.. pretty please :)

Here's what I got now:

<?php
/**
* Implementation of hook_menu().
* Adds a menu tab to the User menu.
*/
function menutweaks_menu() {
  $items['user/%user'] = array(
    'title' => 'USE REG KEY',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('og_reg_keys_join'),
    'weight' => 10,
    'access callback' => TRUE,
    'type' => MENU_LOCAL_TASK,
  );

  return $items;
}

One small thing, you should

One small thing, you should wrap your 'title' value inside the t() function.
Ex: 'title' => t('USE REG KEY'),

Correct, but not climbed that

Correct, but not climbed that particular mountain yet. My tab and page do not work yet! Thanks for input, all helps! Cheers

Where exactly do you want to

Where exactly do you want to put the tab? user/%user might override the profile view altogether. user/%/something would put it on one level with 'View' and 'Contact'.

(The difference between % and %user is that the latter would result in user_load() being executed on the argument and the loaded object passed to the page callback; that doesn't seem necessary here.)

Ok, when the users visits his

Ok, when the users visits his user page i.e. user/1 or user/813 the tab should magically appear!

Then we need to ensure the

Then we need to ensure the tab appears only when viewing one's own profile page and not when viewing others'.

<?php
/**
* Implementation of hook_menu().
* Adds a menu tab to the User menu.
*/
function menutweaks_menu() {
 
$items['user/%/regkey'] = array(
   
'title' => 'USE REG KEY',
   
'page callback' => 'drupal_get_form',
   
'page arguments' => array('og_reg_keys_join'),
   
'weight' => 10,
   
'access callback' => 'menutweaks_tab_access',
   
'access arguments' => array(1),
   
'type' => MENU_LOCAL_TASK,
  );
  return
$items;
}

/**
* Helper function - determine if the user is viewing their own profile page.
*/
function menutweaks_tab_access($uid) {
  global
$user;
  if (
$uid == $user->uid) {
    return
TRUE;
  }
  else {
    return
FALSE;
  }
}
?>

Wow, it works! Oh man, I see

Wow, it works! Oh man, I see you changed the initial code and added more, throw me a fish and let me know what's going on here please?

Minor thing, the tab ain't

Minor thing, the tab ain't themed properly. have I got to wrap that in a some sort of command?

How seriously improper does

How seriously improper does it look - got a screenshot? It should look just like other tabs of the same level (e.g. 'Contact' on other users' profiles).

What I added was to

What I added was to change

'access callback' => TRUE,

which means "give access to everyone, always", to
'access callback' => 'menutweaks_tab_access',
'access arguments' => array(1),

which means "take that second variable part of the path and pass it to menutweaks_tab_access, and it will tell us whether access should be awarded or not".
menutweaks_tab_access returns TRUE ("give access") if, for example, user with ID 22 is looking at user/22 (his own profile), and FALSE ("deny access") if they're looking at user/23 (other user's profile). The tab is displayed only if the user has access to it.

Thanks dude, very good of you

Thanks dude, very good of you to help me out and supply the info to make the whole thing complete. I kind of guessed that is what you had changed, but guessing and knowing are two very different things :)
As for the tab, one of the rounded corners was missing so I just added a bit of CSS and now it is perfect!

Thanks again Drave Robber, you might be interested to know that the great grand daddy of all grave robbers was publicly strung up in my home town on the 28th January almost 200 years ago http://en.wikipedia.org/wiki/Burke_and_Hare_murders

Cheers, dude!

nobody click here