2

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:

  1. 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?

  2. 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,

1 Answer 1

1

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().
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.