Drupal Sites: Launching With Zero Update Hooks

Drupal Sites: Launching with zero update hooks... and 5 other reasons to use Drupal's custom_config module.

The SmartCentres project was built using an "installation profile" development strategy.

For those who are not familiar with it, the brief summary mentions a cleaner, leaner codebase resulting in a more stable development process that is reproducible from team member to team member. Many Drupal teams are using this process and this is fantastic step forward.

The Custom Config module can be found on Github and aims to build on top of the "installation profile" development strategy.

A faster way to update. hook_update_N is a great place for database alters, data migration, or other larger tasks. In our workflow, however, we've been using hook_update_N to execute single lines such as module_enable('some_module') or variable_set('some_var', 123). This leads to install files being way larger and uglier than they should be. "Run Install Hooks", and "Run Post Install" are introduced to replace the need for hook_update_N. Hitting the "Run Install Hooks" or "Run Post Install" callback pages will use the module's own custom_config_module_implements function to find hooks and install files only from our custom or features modules. In order for this to happen, custom and features modules must use the folder structure convention of modules/custom or modules/features. But, all other contrib install hooks are ignored, so we're free to safely hit the "Run Post Install" page without worry of contrib modules.

Helper functions. If you're creating or updating blocks, running queries, or adding terms, Custom Config is there to help. We've got a small handful of hooks you can implement to do most of these setup tasks. Checkout custom_config.api.php to find out how to implement these.

The ever exciting post-install phase. Block modifications, queries, and terms are all executed after the entire site is built. Using hook_init and a custom variable, the module is able to tell if this is the first time a page is being hit after installing. This is important if you need to ensure that features modules are installed and have properly setup their respective blocks, vocabularies, or some other requirement is met. Also, using hook_postinstall you can run any commands after ensuring that the entire site is installed and configured.

A place for custom configuration. From time to time, a project requires a custom configuration form. The question eventually pops up, where does this page live? There's never a single good answer to this, custom_config tries to help by creating a menu item where custom configuration forms should live. Also, that page has two tabs by default "Run Install Hooks", and "Run Post Install" which simply serve as callbacks

Drush integration. If you're into drush, and I don't know why you wouldn't be, then you'll be happy to hear that both callbacks to run the install and post-install hooks are available as drush commands: drush cc-ri and drush cc-rpi

So, the next time you're starting a project as an installation profile, give custom_config a look over, and think about how it might help you!

Written by

Sebastian Lesch

Sebastian Lesch

Sign up for our newsletter