Wrong way to overwrite a menu

KiamLaLuno - August 7, 2008 - 04:11
Project:EveryBlog
Version:6.x-1.3-beta1
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:active
Description

In Drupal 6, the right way to redefine a menu of another module is to implement hook_menu_alter().

#1

ntroutman - August 7, 2008 - 04:48

What are you revering to? What menu irme am I overwriting incorrectly? More specific information would be helpful. Thanks for taking the time to post though.

Regards,
Ntroutman

#2

KiamLaLuno - August 7, 2008 - 16:28

In everyblog.module, the function everyblog_menu() contains the following definition for a menu item:

<?php
    $blogs
= array();
   
$items['blog/%'] = array(
       
'page callback' => 'everyblog_page',
       
'page arguments' => array(1),
       
'access callback' => 'everyblog_page_user_access',
       
'access arguments' => array(1),
       
'type' => MENU_CALLBACK,
       
'file' => 'everyblog.pages.inc',
    );
?>

That menu item is already defined from blog.module, therefore everyblog.module must implement hook_menu_alter() to alter such menu.

I hope this helps to understand the issue I am talking of.
Regards,
Kiam

#3

ntroutman - August 7, 2008 - 18:12

Except that I'm not overwriting an existing menu since EveryBlog is incompatible with the core Blog module and expects it to me disabled. Without the core Blog module there is no menu item to overwrite. At least that is how I understand things to work. I'll look into more carefully later. Thanks for the post.

Regards,
NTroutman

#4

KiamLaLuno - August 7, 2008 - 18:27

Except that I'm not overwriting an existing menu since EveryBlog is incompatible with the core Blog module and expects it to be disabled.

That is not stated in the project page. I was thinking the module was just an extension for blog.module which then could co-exist with it.
If the module requires the core module to be disabled, then it should check that at runtime, and report an error in such case (the checking can be done in the implementation of hook_requirements()).

Until blog.module has not been disabled, everyblog.module is re-defining an already existing menu.

#5

ntroutman - August 7, 2008 - 18:40

Thanks for the info. I didn't know about the hook_requirements. I'll make the change to the project page and add the needed code. Thanks again

#6

KiamLaLuno - August 7, 2008 - 19:04

I usually put a link to the documentation page, but this time I forgot to do it.
As the documentation for the hook states, the checking can be done when the module is being installed, or when the module is being executed; in the first case, if the hook implementation returns an error code, the installation of the module gets stopped.

#7

ntroutman - August 7, 2008 - 20:29

Thanks for the link. I'm working on making the fix right now, beta2 should be out later today.

Regards,
NTroutman

 
 

Drupal is a registered trademark of Dries Buytaert.