Weight-related issues

Photo of Greg Harvey
Sat, 2008-01-26 01:27By greg

I was aware of the 'system' table in the Drupal 5.x database. It provides all sorts of options for installed modules, but it is one of those things that is little-understood and often ignored.

Today I encountered issues specifically relating to a single column in the 'system' table: I am building another site using the e-Commerce module, but this time I have to change the available items in a form array. Problem! Many of the e-Commerce module form elements are not available when you print the contents of $form to screen, within the context of hook_form_alter, in a normal module.

This is because e-Commerce installs itself in the 'system' table of Drupal 5.x with a 'weight' of 5. Like weight when it is used for fields/menu items, weight with modules means the higher the number, the later in the process order a module will be invoked. -2 will be processed before 0, which will be processed before 2.

Now, because e-Commerce has a weight of 5 you cannot get a handle on any fields added by the e-Commerce module in hook_form_alter unless your module has a weight higher (heavier) than 5.

Actually, most modules have a default weight of 0, so if you want to be certain your module will have all information available to it when hooks are invoked, it needs to have a weight which places it last in the process order.

If all modules are weighted with a 0, filename of the module's .info file dictates the process order (alphabetically).

So, basically, the only way to be sure your module will be processed last (and thus be able to use hooks such as hook_form_alter successfully) is to ensure it's weight is higher than all other installed modules.