chosen.install 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <?php
  2. /**
  3. * @file
  4. * Installation and uninstallation functions.
  5. */
  6. /**
  7. * Implements hook_requirements().
  8. */
  9. function chosen_requirements($phase) {
  10. $requirements = array();
  11. module_load_include('module', 'chosen');
  12. $t = get_t();
  13. $chosen_path = chosen_get_chosen_path();
  14. switch ($phase) {
  15. case 'runtime':
  16. if (!$chosen_path) {
  17. $requirements['chosen_js'] = array(
  18. 'title' => $t('Chosen JavaScript file'),
  19. 'severity' => REQUIREMENT_ERROR,
  20. 'description' => $t('You need to download the !chosen and extract the entire contents of the archive into the %path directory on your server.', array(
  21. '!chosen' => l($t('Chosen JavaScript file'), CHOSEN_WEBSITE_URL),
  22. '%path' => 'sites/all/libraries')),
  23. 'value' => $t('Not Installed'),
  24. );
  25. }
  26. else {
  27. $requirements['chosen_js'] = array(
  28. 'title' => $t('Chosen JavaScript file'),
  29. 'severity' => REQUIREMENT_OK,
  30. 'value' => $t('Installed'),
  31. );
  32. }
  33. break;
  34. }
  35. return $requirements;
  36. }
  37. /**
  38. * Implements hook_uninstall().
  39. */
  40. function chosen_uninstall() {
  41. // Delete created variables.
  42. variable_del('chosen_minimum_single');
  43. variable_del('chosen_minimum_multiple');
  44. variable_del('chosen_minimum_width');
  45. variable_del('chosen_search_contains');
  46. variable_del('chosen_jquery_selector');
  47. variable_del('chosen_placeholder_text_multiple');
  48. variable_del('chosen_placeholder_text_single');
  49. variable_del('chosen_no_results_text');
  50. variable_del('chosen_disabled_themes');
  51. variable_del('chosen_disable_search');
  52. variable_del('chosen_disable_search_threshold');
  53. variable_del('chosen_allow_single_deselect');
  54. variable_del('chosen_include');
  55. }
  56. /**
  57. * Implements hook_update_N().
  58. *
  59. * Transfer the old chosen minimum value to the new chosen minimum single and
  60. * chosen minimum multiple variables.
  61. */
  62. function chosen_update_7201() {
  63. $chosen_minimum = variable_get('chosen_minimum', 20);
  64. variable_set('chosen_minimum_single', $chosen_minimum);
  65. variable_set('chosen_minimum_multiple', $chosen_minimum);
  66. variable_del('chosen_minimum');
  67. }
  68. /**
  69. * Fix variables that should be integers and not strings.
  70. */
  71. function chosen_update_7202() {
  72. $variables = array(
  73. 'chosen_minimum_single',
  74. 'chosen_minimum_multiple',
  75. 'chosen_disable_search_threshold',
  76. );
  77. foreach ($variables as $variable) {
  78. $value = variable_get($variable, 0);
  79. if (!is_numeric($value)) {
  80. variable_set($variable, 0);
  81. }
  82. }
  83. }
  84. /**
  85. * Implements hook_update_N().
  86. *
  87. * Update any option_select widgets with an empty Chosen setting
  88. * to the 'No preference' Chosen setting.
  89. */
  90. function chosen_update_7203() {
  91. $field_names = db_query("SELECT field_name FROM {field_config_instance} WHERE data LIKE :widget", array(':widget' => '%' . db_like('options_select') . '%' . db_like('apply_chosen') . '%'))->fetchCol();
  92. if (empty($field_names)) {
  93. return;
  94. }
  95. $instances = field_read_instances(array('field_name' => $field_names));
  96. foreach ($instances as $instance) {
  97. if ($instance['widget']['type'] == 'options_select' && empty($instance['widget']['settings']['apply_chosen'])) {
  98. $instance['widget']['settings']['apply_chosen'] = '';
  99. field_update_instance($instance);
  100. }
  101. }
  102. }
  103. /**
  104. * Implements hook_update_N().
  105. *
  106. * Set the 'Disable the default Chosen theme' Chosen setting to the opposite
  107. * of the current general'Use the default chosen theme'
  108. * Chosen setting for all enabled themes.
  109. */
  110. function chosen_update_7204() {
  111. module_load_include('inc', 'chosen', 'chosen.admin');
  112. $chosen_use_theme_setting = variable_get('chosen_use_theme', TRUE);
  113. // We now chose to disable the default Chosen CSS instead of deselecting
  114. // the 'Use the default chosen theme' option box.
  115. if (!$chosen_use_theme_setting) {
  116. $themes = system_list('theme');
  117. foreach ($themes as $theme) {
  118. // Only create options for enabled themes.
  119. if ($theme->status) {
  120. $options[$theme->name] = $theme->info['name'];
  121. }
  122. }
  123. variable_set('chosen_disabled_themes', array_keys($options));
  124. }
  125. // Delete the old variable.
  126. variable_del('chosen_use_theme');
  127. }