hs_taxonomy.install 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <?php
  2. /**
  3. * @file
  4. * Install file for the Hierarchical Select Taxonomy module.
  5. */
  6. /**
  7. * Implementation of hook_uninstall().
  8. */
  9. function hs_taxonomy_uninstall() {
  10. db_delete('variable')
  11. ->condition('name', 'taxonomy_hierarchical_select_%', 'LIKE')
  12. ->execute();
  13. variable_del('taxonomy_override_selector');
  14. }
  15. /**
  16. * Implementation of hook_enable().
  17. */
  18. function hs_taxonomy_enable() {
  19. variable_set('taxonomy_override_selector', TRUE);
  20. drupal_set_message(t("Drupal core's taxonomy selects are now overridden on the
  21. Taxonomy Term form. They've been replaced by
  22. Hierarchical Selects for better scalability.<br />
  23. You can <a href=\"!configure-url\">configure</a> it to
  24. be used on node forms too!",
  25. array(
  26. '!configure-url' => url('admin/config/content/hierarchical_select/configs'),
  27. )));
  28. }
  29. /**
  30. * Implementation of hook_disable().
  31. */
  32. function hs_taxonomy_disable() {
  33. variable_set('taxonomy_override_selector', FALSE);
  34. drupal_set_message(t("Drupal core's taxonomy selects are now restored.
  35. Please remember that they're not scalable!."),
  36. 'warning');
  37. }
  38. //----------------------------------------------------------------------------
  39. // Schema updates.
  40. /**
  41. * Upgrade path from Drupal 6 to Drupal 7 version of Hierarchical Select:
  42. * - delete the taxonomy_override_selector variable if it exists.
  43. */
  44. function hs_taxonomy_update_7300() {
  45. variable_del('taxonomy_override_selector');
  46. }
  47. /**
  48. * Apparently, taxonomy_override_selector still exists in *one* location in
  49. * Drupal 7 core: on the form_taxonomy_form_term form (where you can create or
  50. * edit a Taxonomy term).
  51. */
  52. function hs_taxonomy_update_7301() {
  53. variable_set('taxonomy_override_selector', TRUE);
  54. }
  55. /**
  56. * Convert Taxonomy vocabulary config IDs to use machine name instead of serial
  57. * vocabulary ID.
  58. */
  59. function hs_taxonomy_update_7302() {
  60. require_once DRUPAL_ROOT . '/' . drupal_get_path('module', 'hierarchical_select') . '/includes/common.inc';
  61. $vocabularies = taxonomy_vocabulary_get_names();
  62. foreach ($vocabularies as $machine_name => $vocabulary) {
  63. $old_config_id = "taxonomy-{$vocabulary->vid}";
  64. $new_config_id = "taxonomy-{$machine_name}";
  65. $old_config = variable_get('hs_config_' . $old_config_id, NULL);
  66. if (!empty($old_config)) {
  67. hierarchical_select_common_config_set($new_config_id, $old_config);
  68. hierarchical_select_common_config_del($old_config_id);
  69. }
  70. }
  71. }
  72. /**
  73. * Convert Taxonomy vocabulary config IDs to use field name.
  74. */
  75. function hs_taxonomy_update_7303() {
  76. require_once DRUPAL_ROOT . '/' . drupal_get_path('module', 'hierarchical_select') . '/includes/common.inc';
  77. foreach (field_info_instances() as $entity_type => $bundles) {
  78. foreach ($bundles as $bundle => $field_list) {
  79. foreach ($field_list as $field_name => $instance) {
  80. if ($instance['widget']['type'] == 'taxonomy_hs') {
  81. $field_info = field_info_field($field_name);
  82. $allowed_value = $field_info['settings']['allowed_values'][0];
  83. $vocabulary_name = $allowed_value['vocabulary'];
  84. $old_config_id = "taxonomy-{$vocabulary_name}";
  85. $new_config_id = "taxonomy-{$field_name}";
  86. $old_config = hierarchical_select_common_config_get($old_config_id);
  87. if (!empty($old_config)) {
  88. hierarchical_select_common_config_set($new_config_id, $old_config);
  89. }
  90. }
  91. }
  92. }
  93. }
  94. }
  95. /**
  96. * Cleanup old-named configs.
  97. */
  98. function hs_taxonomy_update_7304() {
  99. require_once DRUPAL_ROOT . '/' . drupal_get_path('module', 'hierarchical_select') . '/includes/common.inc';
  100. $vocabularies = taxonomy_get_vocabularies();
  101. foreach ($vocabularies as $vid => $vocabulary) {
  102. $old_config_id = "taxonomy-{$vocabulary->machine_name}";
  103. hierarchical_select_common_config_del($old_config_id);
  104. }
  105. }