Overcoming the Drupal pain

24 Oct 2012

So, I have been building a Drupal module. I've learned a lot about its architecture.

But, there is one pain from building a module:

  • when enabled, your module needs to install a database schema
  • you module adds things to the admin menu

What I did is to disable the module and re-enable it. I could feel my brain cells died from boredom.

However, I've discovered a painless way to do it:

In your module, create `hook_init()` and, within it, rebuild the admin menu, disable module and enable module. Here is the code:

function your_module_init() { menu_rebuild(); module_disable(array('your_moduleyour_module')); module_enable(array('your_module')); // drupal_flush_all_caches(); }
  • Using `drupal_flush_all_caches()disables ``drupal_set_message```

You can uncomment `drupal_flush_all_caches()` if you feel something behave strangely. (Because Drupal might cache the result.)

Give it a kudos