shortcut.install 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <?php
  2. /**
  3. * @file
  4. * Install, update and uninstall functions for the shortcut module.
  5. */
  6. /**
  7. * Implements hook_install().
  8. */
  9. function shortcut_install() {
  10. $t = get_t();
  11. // Create an initial default shortcut set.
  12. $shortcut_set = new stdClass();
  13. $shortcut_set->title = $t('Default');
  14. $shortcut_set->links = array(
  15. array(
  16. 'link_path' => 'node/add',
  17. 'link_title' => $t('Add content'),
  18. 'weight' => -20,
  19. ),
  20. array(
  21. 'link_path' => 'admin/content',
  22. 'link_title' => $t('Find content'),
  23. 'weight' => -19,
  24. ),
  25. );
  26. // If Drupal is being installed, rebuild the menu before saving the shortcut
  27. // set, to make sure the links defined above can be correctly saved. (During
  28. // installation, the menu might not have been built at all yet, or it might
  29. // have been built but without the node module's links in it.)
  30. if (drupal_installation_attempted()) {
  31. menu_rebuild();
  32. }
  33. shortcut_set_save($shortcut_set);
  34. }
  35. /**
  36. * Implements hook_uninstall().
  37. */
  38. function shortcut_uninstall() {
  39. drupal_load('module', 'shortcut');
  40. // Delete the menu links associated with each shortcut set.
  41. foreach (shortcut_sets() as $shortcut_set) {
  42. menu_delete_links($shortcut_set->set_name);
  43. }
  44. }
  45. /**
  46. * Implements hook_schema().
  47. */
  48. function shortcut_schema() {
  49. $schema['shortcut_set'] = array(
  50. 'description' => 'Stores information about sets of shortcuts links.',
  51. 'fields' => array(
  52. 'set_name' => array(
  53. 'type' => 'varchar',
  54. 'length' => 32,
  55. 'not null' => TRUE,
  56. 'default' => '',
  57. 'description' => "Primary Key: The {menu_links}.menu_name under which the set's links are stored.",
  58. ),
  59. 'title' => array(
  60. 'type' => 'varchar',
  61. 'length' => 255,
  62. 'not null' => TRUE,
  63. 'default' => '',
  64. 'description' => 'The title of the set.',
  65. ),
  66. ),
  67. 'primary key' => array('set_name'),
  68. 'foreign keys' => array(
  69. 'menu_name' => array(
  70. 'table' => 'menu_links',
  71. 'columns' => array('set_name' => 'menu_name'),
  72. ),
  73. ),
  74. );
  75. $schema['shortcut_set_users'] = array(
  76. 'description' => 'Maps users to shortcut sets.',
  77. 'fields' => array(
  78. 'uid' => array(
  79. 'type' => 'int',
  80. 'unsigned' => TRUE,
  81. 'not null' => TRUE,
  82. 'default' => 0,
  83. 'description' => 'The {users}.uid for this set.',
  84. ),
  85. 'set_name' => array(
  86. 'type' => 'varchar',
  87. 'length' => 32,
  88. 'not null' => TRUE,
  89. 'default' => '',
  90. 'description' => "The {shortcut_set}.set_name that will be displayed for this user.",
  91. ),
  92. ),
  93. 'primary key' => array('uid'),
  94. 'indexes' => array(
  95. 'set_name' => array('set_name'),
  96. ),
  97. 'foreign keys' => array(
  98. 'set_user' => array(
  99. 'table' => 'users',
  100. 'columns' => array('uid' => 'uid'),
  101. ),
  102. 'set_name' => array(
  103. 'table' => 'shortcut_set',
  104. 'columns' => array('set_name' => 'set_name'),
  105. ),
  106. ),
  107. );
  108. return $schema;
  109. }