1

My module creates blocks. These may come and go and I want to make sure I'm not leaving cruft behind, e.g. settings from the configure block screen for blocks that no longer exist (i.e. are no longer returned by my hook_block_info()).

I've noticed that removing a block and then adding a new one (with the same delta) magically brings up the old config.

What should I do in my module to clean out this config? (or is it somehow done for me in an occasional cron?)

2 Answers 2

1

I hope this should work if I get your question right.

db_delete('block')
  ->condition('module', MODULE)
  ->condition('delta', DELTA)
  ->execute();
db_delete('block_node_type')
  ->condition('module', MODULE)
  ->condition('delta', DELTA)
  ->execute();
db_delete('block_role')
  ->condition('module', MODULE)
  ->condition('delta', DELTA)
  ->execute();

cache_clear_all(MODULE_DELTA, 'cache_block');

Where MODULE resembles your module name and DELTA resembles your block's delta.

0

Block configuration might be saving through variable_set();

Run a query on your database, as

SELECT * FROM system WHERE name LIKE '%block%';

Replace %block% with your with probable block configuration form fields machine name, to check if there is a variable

Also in your custom module check the implementation side hook_block_save(), if any varibale_set(); is there.

In case this is the problem you can implement hook_uninstall inside which you can do variable_delete('name_of_vraible_to_delete');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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