Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By afuna on
Hey
I have this very simple code:
function mymodule_menu() {
$items = array();
dpm('mymodule_menu');
$items['di/gr/%grpid/edit'] = array(
'title' => 'Edit group',
'page callback' => 'mymodule_group_edit',
'page arguments' => array(2),
'access callback' => TRUE,
'type' => MENU_NORMAL_ITEM,
);
return $items;
}
function mymodule_group_edit($grp) {
watchdog('debug', 'mymodule_group_edit');
dpm('mymodule_group_edit');
$form = new array();
$form['access'] = array(
'#type' => 'fieldset',
'#title' => t('Access log settings'),
'#tree' => TRUE,
);
return $form;
}
I have verified mymodule_menu is called using that simple dpm function call, but "mymodule_group_edit" never gets called when i access that path.
I tried clearing the cache and also stopping the entire apache server.
Also tested with MENU_CALLBACK and got the same results.
What am I doing wrong? I went through many examples online and went through the hook_menu API with zero success.
Thanks.
Comments
First off, please wrap your
First off, please wrap your code in <?php ?> tags to make it more readable for us.
Now, as to your problem, I'm guessing it's as follows. Look at this:
By setting your wildcard as %grpid, Drupal is going to look for a function named grpid_load(). It will pass the value of the wildcard to this function. The value returned from that function is then passed to your page callback. If you don't have that function, or that function returns FALSE (or nothing), then your callback function is never called.
You didn't show a function named grpid_load(). Does it exist? If it does, does it return a value? If it doesn't exist, then you either need to create this function, or change your path to this:
I dont have grpid_load() so I
I dont have grpid_load() so I did as you suggested in your second code snippet.
Now it works!
Thanks for the help.
Menu callback
Solved my problem too, thank you very much Jaypan.