Block API module changes coming soon

After reviewing and updating Block API for Drupal 7, I saw that there were some fairly big changes made to the way the block system works from a code perspective which meant I have had to change a fair bit of the module for Drupal 7. So rather than having 2 quite distinct bits of code, I will be updating the Drupal 6 version to work like the Drupal 7 version so that the documentation is the same. This not only makes the module easier to maintain from my perspective but also anyone else using Block API.

So what has changed?

hook_block() no longer exists in Drupal 7. It has been split in to individual hooks for each $op. So rather than hook_block() we now have:

  • hook_block_info()
  • hook_block_configure()
  • hook_block_save()
  • hook_block_view()

A few of these new hooks conflicted with the hooks put in place by the Block API module, so I have made a few changes to the way other modules hook in to it.

<?phpfunction html_block_block($op = 'list', $delta = NULL, $edit = array()) {
  $function = 'block_api_block_'. $op;
  return $function('html_block', $delta, $edit);
}?>

The above has gone completely. Rather than passing the modules name to the core Blocks module, Block API will pass on it's own name and handle the block management of modules using the API itself. This reduces the amount of code needed (although it wasn't that much to start off with) and also makes it easier to remember what you need to use to hook in to Block API.

hook_block_api_info() has now changed to hook_block_api_block_types(), the code stays exactly the same. This was caused by the function name changes made in Drupal 7.

hook_block_api_view() has changed to hook_block_api_display(), this was also due to the function change in Drupal 7.

Everything else stays the same. The Block API has now been made slightly easier to use and hook in to thanks to Drupal 7.

The code on d.o should be updated soon.