dashboard.install 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. /**
  3. * @file
  4. * Install, update and uninstall functions for the dashboard module.
  5. */
  6. /**
  7. * Implements hook_disable().
  8. *
  9. * Stash a list of blocks enabled on the dashboard, so they can be re-enabled
  10. * if the dashboard is re-enabled. Then disable those blocks, since the
  11. * dashboard regions will no longer be defined.
  12. */
  13. function dashboard_disable() {
  14. // Stash a list of currently enabled blocks.
  15. $stashed_blocks = array();
  16. $result = db_select('block', 'b')
  17. ->fields('b', array('module', 'delta', 'region'))
  18. ->condition('b.region', dashboard_regions(), 'IN')
  19. ->execute();
  20. foreach ($result as $block) {
  21. $stashed_blocks[] = array(
  22. 'module' => $block->module,
  23. 'delta' => $block->delta,
  24. 'region' => $block->region,
  25. );
  26. }
  27. variable_set('dashboard_stashed_blocks', $stashed_blocks);
  28. // Disable the dashboard blocks.
  29. db_update('block')
  30. ->fields(array(
  31. 'status' => 0,
  32. 'region' => BLOCK_REGION_NONE,
  33. ))
  34. ->condition('region', dashboard_regions(), 'IN')
  35. ->execute();
  36. }
  37. /**
  38. * Implements hook_enable().
  39. *
  40. * Restores blocks to the dashboard that were there when the dashboard module
  41. * was disabled.
  42. */
  43. function dashboard_enable() {
  44. global $theme_key;
  45. if (!$stashed_blocks = variable_get('dashboard_stashed_blocks')) {
  46. return;
  47. }
  48. if (!$admin_theme = variable_get('admin_theme')) {
  49. drupal_theme_initialize();
  50. $admin_theme = $theme_key;
  51. }
  52. foreach ($stashed_blocks as $block) {
  53. db_update('block')
  54. ->fields(array(
  55. 'status' => 1,
  56. 'region' => $block['region']
  57. ))
  58. ->condition('module', $block['module'])
  59. ->condition('delta', $block['delta'])
  60. ->condition('theme', $admin_theme)
  61. ->condition('status', 0)
  62. ->execute();
  63. }
  64. variable_del('dashboard_stashed_blocks');
  65. }
  66. /**
  67. * Implements hook_uninstall().
  68. */
  69. function dashboard_uninstall() {
  70. variable_del('dashboard_stashed_blocks');
  71. }