How to disable and enable Drupal 7 blocks programmatically
Sometimes you need to enable and place a Drupal 7 block in a seen region like header, content, footer, etc., and other times you need to disable it programmatically in a custom module. So to do it you just need to create two functions:
function _start_refreshing() {
db_update('block')
->fields(array(
'status' => 1,
'weight' => -10,
'region' => 'footer',
))
->condition('module', 'mymodule')
->condition('delta', 'mymodule_delta')
->execute();
}
and
function _stop_refreshing() {
db_update('block')
->fields(array(
'status' => 0,
'weight' => -10,
'region' => 'disabled',
))
->condition('module', 'mymodule')
->condition('delta', 'mymodule_delta')
->execute();
}
and call one of the functions as needed:
_start_refreshing();
Add new comment