[development] reducing module size

Gordon Heydon gordon at heydon.com.au
Wed Feb 2 12:58:39 UTC 2011


to make a module load, the module can be an empty file but will not do much.

For drupal 6.x you need to load in your hook functions into the .module file, but with things like hook_menu() you can specify which file to load when executing this menu item, which will allow you to move more out of the main module which is loaded everytime.

With Drupal 7.x there you can move all your hooks out of the module file, since hooks can be registered and grouped they can be moved out into other files with the group,  see http://api.drupal.org/api/drupal/modules--system--system.module/function/system_hook_info/7 which shows that some of the token hooks are registered and can be moved to a file modulename.token.inc

Pity more hooks are not registered.

There are also other things you can do like implement a hook implementation and then load an include file and execute the real function.


On 02/02/2011, at 11:46 PM, Bob Hutchinson wrote:

> I have a module whose functions are only used by logged-in users, it provides 
> nothing to 'Anonymous' users except for a block.
> I'm considering loading most of the functions only when $user->uid > 0 
> probably in hook_init()
> My question is, which functions would have to be loaded in order for things 
> not to break, apart from the block functions (and any that it uses)?
> Any insights would be most welcome before I try it out.
> -- 
> -----------------
> Bob Hutchinson
> Midwales dot com
> -----------------

More information about the development mailing list