Weights are not the solution? Re: [development] altering an alteredform

Nedjo Rogers nedjo at islandnet.com
Fri Jun 9 14:08:14 UTC 2006


Yes. Messing around with weights is a stopgap solution for 4.7, but indeed 
we need something better. And order of operations is only getting more 
needed rather with less, as we work more with extending existing behaviours 
through form_alter, db_rewrite_sql, etc.

A concrete example: I'm working with a module that wants to come after 
user.module but before node.module. Yes, I can reset the weights of one or 
both of those core modules, but it's an obvious hack that will fail as soon 
as someone else tries to do the same.

An limited and trouble-prone alternative right now is to explicitly call 
another module's method. If, e.g., my form_alter needs to come before 
node.module's, I can call node_form_alter() at the end of my 
example_form_alter() call.

The issue and both of Ber's suggestions seem worth some more attention.

  * roundtrips.
  * Hook registration.

Key to this is that it isn't absolute order of modules that's the issue; 
it's the order of particular calls. It's quite feasible, for example, that 
example_form_alter needs to come before node_form_alter, but example_menu 
after node_menu.

Maybe a simple (?) solution would be to register not all hooks but only 
their dependencies.

function example_hook_dependencies() {
  return array(
    'form_alter' => array(
      '#before' => array('node'),
      '#after' => array('user')
    ),
    'menu' => array(
      '#before' => array('node')
    )
  );
}

(Or, alternately, I suppose, these data could be coded into an install 
metadata file.)

Then module_invoke_all evaluates these dependencies and orders its calls 
accordingly. 



More information about the development mailing list