I experimented with extending Storm. I added a common function, storm_xx(), in storm.module and used the function in stormattribute.module. storm_extra() was not loaded when stormattribute_menu() tried to use the function. Can the load order be controlled to ensure storm.module is loaded first?

Comments

Roberto Gerola’s picture

Status: Active » Closed (works as designed)

> storm_extra() was not loaded when stormattribute_menu() tried to use the function
Not sure you can do this in the hook of menu.

> Can the load order be controlled to ensure storm.module is loaded first?
Yes, take a look at the weight field in the system table.

peterx’s picture

Status: Closed (works as designed) » Closed (fixed)

hook_init says it is run after all modules are loaded. hook_menu does not say when it is run but it can use stuff from hook_init so hook_menu must be run after all modules are loaded. I tried the change in another module and it worked. Perhaps the problem was by my FTPing stuff the wrong way round when when I first tried the change.

The actual change is to replace the storm directory name with a string from a central function so I can change the configuration in one place. I define the function containing the string in storm.module and use the function wherever there is a path in the modules I am using. I am adding one module at a time to see what each module does.

drupalfever’s picture

Component: Code » Storm.module

I know that this post was made long ago but I am posting an answer to help out future Drupalers.

There is actually a way to request Drupal to load your module before others. You will have to change the weight of your module on the database.

The database table that you will have to alter is called "system". This table has a record of all the modules and themes that you are using on your website. You will have to change the weight of your module so it is lighter than any other module.

Following is an example of PHP code that you could put on the "storm" module that would make sure that your module is always the first to load:

  
  //Grab from the database the weight of the module that is currently loading first.
  $query = db_query("SELECT weight FROM {system} WHERE type='module' AND name!='storm' ORDER BY weight ASC LIMIT 1");
  $array = db_fetch_array($query);
  $weight = $array['weight'] -1;
  
  //Change the weight of the "storm" module so it is lighter than the previously lightest module.
  db_query("UPDATE {system} SET weight=%d WHERE name='storm' AND type='module'", $weight);

The above code should be placed on the "storm_init" function in the module so it will be executed every time a new module is installed.