shortcut.install 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. /**
  3. * @file
  4. * Install, update and uninstall functions for the shortcut module.
  5. */
  6. /**
  7. * Implements hook_schema().
  8. */
  9. function shortcut_schema() {
  10. $schema['shortcut_set_users'] = [
  11. 'description' => 'Maps users to shortcut sets.',
  12. 'fields' => [
  13. 'uid' => [
  14. 'type' => 'int',
  15. 'unsigned' => TRUE,
  16. 'not null' => TRUE,
  17. 'default' => 0,
  18. 'description' => 'The {users}.uid for this set.',
  19. ],
  20. 'set_name' => [
  21. 'type' => 'varchar_ascii',
  22. 'length' => 32,
  23. 'not null' => TRUE,
  24. 'default' => '',
  25. 'description' => "The {shortcut_set}.set_name that will be displayed for this user.",
  26. ],
  27. ],
  28. 'primary key' => ['uid'],
  29. 'indexes' => [
  30. 'set_name' => ['set_name'],
  31. ],
  32. 'foreign keys' => [
  33. 'set_user' => [
  34. 'table' => 'users',
  35. 'columns' => ['uid' => 'uid'],
  36. ],
  37. 'set_name' => [
  38. 'table' => 'shortcut_set',
  39. 'columns' => ['set_name' => 'set_name'],
  40. ],
  41. ],
  42. ];
  43. return $schema;
  44. }
  45. /**
  46. * Implements hook_install().
  47. */
  48. function shortcut_install() {
  49. // Theme settings are not configuration entities and cannot depend on modules
  50. // so to set a module-specific setting, we need to set it with logic.
  51. foreach (['seven', 'claro'] as $theme) {
  52. if (\Drupal::service('theme_handler')->themeExists($theme)) {
  53. \Drupal::configFactory()
  54. ->getEditable("$theme.settings")
  55. ->set('third_party_settings.shortcut.module_link', TRUE)
  56. ->save(TRUE);
  57. }
  58. }
  59. }
  60. /**
  61. * Implements hook_uninstall().
  62. */
  63. function shortcut_uninstall() {
  64. // Theme settings are not configuration entities and cannot depend on modules
  65. // so to unset a module-specific setting, we need to unset it with logic.
  66. foreach (['seven', 'claro'] as $theme) {
  67. if (\Drupal::service('theme_handler')->themeExists($theme)) {
  68. \Drupal::configFactory()
  69. ->getEditable("$theme.settings")
  70. ->clear('third_party_settings.shortcut')
  71. ->save(TRUE);
  72. }
  73. }
  74. }