Acces/See settings page for a custom odule
I upgraded a module from 5 to 6. I only have one problem: I can access the settings page for it, but can not see the contents of it. This is my code:
function agbnagscreen_menu() {
global $user;
$items = array();
if (agbnagscreen_nag($user)) {
// var_dump($_GET['q']); die();
drupal_goto(sprintf('%s/%s', AGBNAGSCREEN_NAGURL, base64_encode($_GET['q'])));
die();
}
$items['admin/settings/agbnagscreen'] = array(
开发者_如何学Go // 'path' => 'admin/settings/agbnagscreen',
'title' => 'AGB nagscreen',
'access callback' => user_access('Einstellungen von AGB aendern'),
//'access' => user_access('Einstellungen von AGB aendern'),
'page callback' => 'drupal_get_form',
'callback arguments' => array('agbnagscreen_settings_fapi'),
);
$items[AGBNAGSCREEN_NAGURL] = array(
// 'path' => AGBNAGSCREEN_NAGURL,
'title' => 'Allgemeine Geschaeftsbedingungen',
'access' => TRUE,
'callback' => 'drupal_get_form',
'callback arguments' => array('agbnagscreen_fapi'),
'type' => MENU_SUGGESTED_ITEM,
);
return $items;
}
I think the problem is cause by this line:
'page callback' => 'drupal_get_form',
Is that correct? How can I write it, that it works?
You might want to read through the Drupal menu system (Drupal 6.x) handbook page to understand the changes to the menu system: you have several problems in your hook_menu
implementation.
- The conditional at the top will never fire: Drupal 6 only calls
hook_menu()
when the menu is rebuilt, not on every page load. - There is no
callback
: usepage callback
. - The
page callback
acceptspage arguments
, notcallback arguments
. - There is
access
: useaccess callback
. access callback
always a string containing the function name, not a function, and defaults to"user_access"
: you need to supplyaccess arguments
.
A modified version of your hook_menu
implementation might be:
function agbnagscreen_menu() {
$items = array();
$items['admin/settings/agbnagscreen'] = array(
'title' => 'AGB nagscreen',
'access arguments' => array('Einstellungen von AGB aendern'),
'page callback' => 'drupal_get_form',
'page arguments' => array('agbnagscreen_settings_fapi'),
);
$items[AGBNAGSCREEN_NAGURL] = array(
'title' => 'Allgemeine Geschaeftsbedingungen',
'access arguments' => array('access content'),
'page callback' => 'drupal_get_form',
'page arguments' => array('agbnagscreen_fapi'),
'type' => MENU_SUGGESTED_ITEM,
);
return $items;
}
精彩评论