Re: [development] Question on Drupal 6 menus
Khalid, One thing looks wrong for sure: 'file' => 'lists.module', I'm not sure if that's causing the problem, but it instructs the menu system to include the module file again. 'file' should only be used with .inc files. Also, don't use t() anywhere - titles, etc are localized dynamically. Finally (and most importantly), the access part is wrong. Since you are using the defaullt callback (user_access), you can have something like this: function lists_menu() { $items = array(); $items['lists'] = array( 'title' => 'Mailing lists', 'page callback' => 'drupal_get_form', 'page arguments' => array('lists_subscribe_form'), 'access arguments' => array('access content'), 'type' => MENU_SUGGESTED_ITEM, ); return $items; }
---------- Forwarded message ---------- From: "Khalid Baheyeldin" <kb@2bits.com> To: development@drupal.org Date: Thu, 3 Jan 2008 20:27:37 -0500 Subject: [development] Question on Drupal 6 menus This is a question for chx, but I posted it publicly so we all benefit from his reply.
I found a weird problem with the menus in D6. Most probably I am missing something obvious, but I am missing what it is.
This does work. Note that the lists inherits from admin, and it is a NORMAL item.
function lists_menu() { $items = array(); $items['admin/lists'] = array( 'title' => t('Mailing lists'), 'page callback' => 'drupal_get_form', 'page arguments' => array('lists_subscribe'), 'access' => user_access('access content'), 'type' => MENU_NORMAL_ITEM, 'file' => 'lists.module', ); return $items; }
This, which is what I want, does not show the lists path anywhere, not under menu as disabled, nothing (I marked the changed lines with an *).
function lists_menu() { $items = array(); * $items['lists'] = array( 'title' => t('Mailing lists'), 'page callback' => 'drupal_get_form', 'page arguments' => array('lists_subscribe'), 'access' => user_access('access content'), * 'type' => MENU_SUGGESTED_ITEM, 'file' => ' lists.module', ); return $items; }
The latter is the one needed so that the path can be enabled or disabled in the menus as needed. This is the way it works on D5.
What is amiss here? -- Khalid M. Baheyeldin 2bits.com, Inc. http://2bits.com Drupal optimization, development, customization and consulting. -- [ Drupal development list | http://lists.drupal.org/ ]
Peter The reason I added the file element is that I got an error on another module (system.admin.inc ...) and that element made it go away. It works now with your changes. Thanks. On Jan 3, 2008 8:53 PM, Peter Wolanin <pwolanin@gmail.com> wrote:
Khalid,
One thing looks wrong for sure:
'file' => 'lists.module',
I'm not sure if that's causing the problem, but it instructs the menu system to include the module file again. 'file' should only be used with .inc files.
Also, don't use t() anywhere - titles, etc are localized dynamically.
Finally (and most importantly), the access part is wrong. Since you are using the defaullt callback (user_access), you can have something like this:
function lists_menu() { $items = array(); $items['lists'] = array( 'title' => 'Mailing lists', 'page callback' => 'drupal_get_form', 'page arguments' => array('lists_subscribe_form'), 'access arguments' => array('access content'), 'type' => MENU_SUGGESTED_ITEM, ); return $items; }
---------- Forwarded message ---------- From: "Khalid Baheyeldin" <kb@2bits.com> To: development@drupal.org Date: Thu, 3 Jan 2008 20:27:37 -0500 Subject: [development] Question on Drupal 6 menus This is a question for chx, but I posted it publicly so we all benefit from his reply.
I found a weird problem with the menus in D6. Most probably I am missing something obvious, but I am missing what it is.
This does work. Note that the lists inherits from admin, and it is a NORMAL item.
function lists_menu() { $items = array(); $items['admin/lists'] = array( 'title' => t('Mailing lists'), 'page callback' => 'drupal_get_form', 'page arguments' => array('lists_subscribe'), 'access' => user_access('access content'), 'type' => MENU_NORMAL_ITEM, 'file' => 'lists.module', ); return $items; }
This, which is what I want, does not show the lists path anywhere, not under menu as disabled, nothing (I marked the changed lines with an *).
function lists_menu() { $items = array(); * $items['lists'] = array( 'title' => t('Mailing lists'), 'page callback' => 'drupal_get_form', 'page arguments' => array('lists_subscribe'), 'access' => user_access('access content'), * 'type' => MENU_SUGGESTED_ITEM, 'file' => ' lists.module', ); return $items; }
The latter is the one needed so that the path can be enabled or disabled in the menus as needed. This is the way it works on D5.
What is amiss here? -- Khalid M. Baheyeldin 2bits.com, Inc. http://2bits.com Drupal optimization, development, customization and consulting. -- [ Drupal development list | http://lists.drupal.org/ ]
-- Khalid M. Baheyeldin 2bits.com, Inc. http://2bits.com Drupal optimization, development, customization and consulting.
On Jan 3, 2008, at 6:28 PM, Khalid Baheyeldin wrote:
The reason I added the file element is that I got an error on another module (system.admin.inc ...) and that element made it go away.
For clarity: system.admin.inc is not a "module". It's an include file that should be included by system.module when it's doing admin-related things. system.module is a module. The .module files for every enabled module are always loaded when bootstrapping Drupal. The performance gain from splitting modules up into .inc files (made easier by the D6 menu changes) is that you don't have to load all the code that's only rarely used in your .module files. Peter's point is that you should never tell the menu system to include a .module file again, since those are *always* loaded. You should only tell the menu system to include a .inc file, never a .module file. Cheers, -Derek (dww)
On Jan 4, 2008 5:46 PM, Derek Wright <drupal@dwwright.net> wrote:
On Jan 3, 2008, at 6:28 PM, Khalid Baheyeldin wrote:
The reason I added the file element is that I got an error on another module (system.admin.inc ...) and that element made it go away.
For clarity:
system.admin.inc is not a "module". It's an include file that should be included by system.module when it's doing admin-related things. system.module is a module. The .module files for every enabled module are always loaded when bootstrapping Drupal. The performance gain from splitting modules up into .inc files (made easier by the D6 menu changes) is that you don't have to load all the code that's only rarely used in your .module files.
I realize it is not a module. What I meant was that another module spat out an error message about system.admin.inc, and when adding the 'file' element (wrongly) that error went away. When I changed the other things Peter pointed out, all was well.
Peter's point is that you should never tell the menu system to include a .module file again, since those are *always* loaded. You should only tell the menu system to include a .inc file, never a .module file.
Yup. Thanks for the extra explanations. -- Khalid M. Baheyeldin 2bits.com, Inc. http://2bits.com Drupal optimization, development, customization and consulting.
participants (3)
-
Derek Wright -
Khalid Baheyeldin -
Peter Wolanin