Dynamicly generated block_info? I am writing a module that enables admins to create entities. One of the fields on the entity is a cut-off date.

For each entity within the cut-off date a block is produced. I do this by means of a EntityFieldQuery inside hook_block_info.

The user can then configure those blocks to appear on certain paths.

This approach seems to be working, but I'm a little unsure:


is it safe (i.e. reliable)? I'm unsure how drupal handles all the config for blocks - if the block does not exist any more is its config all deleted?
is it an efficiency nightmare? Currently it's only searching a handful of entities for in-date ones, but I'm interested to know if there could be a more efficient way because I guess this will run for every single page load.


Thanks,
RE 1: If the block no longer appears in the hook_block_info(), then yes, the block's config will eventually be removed. I'm a little unsure of the timing (clearing cache / cron operation). You can use _block_rehash() to force an update of the available blocks.

RE 2: Not a nightmare, no. Keep an eye on your entities to ensure the list doesn't get out of control, but that's all you need to worry about. hook_block_info() doesn't get called on every page load, but rather only when:


the cache is cleared
the blocks administration page is loaded
another module calls _block_rehash().