Function naming

Events happening in the community are now at Drupal community events on www.drupal.org.
nicktr's picture

Hi,

I've made a custom module to hold a number of custom functions - one being hook_menu_alter

All the examples I can find show the hook_menu_alter function name using the module name e.g.

  • module name: customsitefucntions

function customsitefucntions_menu_alter(&$items) {

Does it have to follow this convention? What if I want to add another hook_menu_alter function in the same module?

Could it be:

function anotherFucntion_menu_alter(&$items) {

Thanks,

Nick

Comments

Ok so I tried removing the

nicktr's picture

Ok so I tried removing the module name of my hook_menu_alter and replacing it with another name, and it broke it.
So, I guess you would only ever use 1 hook_menu_alter in a particular module, as you can target any menu you want from there, so there wouldn't be a need for another!?

Unfortunately that's the

kelvinleehk's picture

Unfortunately that's the case.

hook_menu_alter is a hook, which is automatically called at a certain state if system notice a hook function defined with specific naming convention, e.g. modulename_menu_alter for modules and theme_menu_alter for template.php (please correct me if I'm wrong :P).

However, your module can have functions that don't start with "modulename", though they will be considered as a custom function and they will only be executed if they are called in other hooks IIRC

function modulename_menu_alter() {
customfunc();
}

function customfunc () {
// do something
}

I see, thanks for explaining,

nicktr's picture

I see,
thanks for explaining, Kelvin.

Nick

DrupalHK

Group categories

HKDUG Vocabulary

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: