languageicons.install 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. /**
  3. * @file
  4. * Install, update, and uninstall functions for Language Icons.
  5. */
  6. /**
  7. * Implements hook_install().
  8. */
  9. function languageicons_install() {
  10. // Convert old "i18n_icon_*" variables, if any.
  11. _languageicons_convert_i18n_icon_variables();
  12. }
  13. /**
  14. * Implements hook_uninstall().
  15. */
  16. function languageicons_uninstall() {
  17. // Clear any variables that might be in use
  18. $variables = array(
  19. 'languageicons_show_node',
  20. 'languageicons_show_block',
  21. 'languageicons_placement',
  22. 'languageicons_path',
  23. 'languageicons_size',
  24. 'languageicons_show_tooltip',
  25. );
  26. foreach ($variables as $variable) {
  27. variable_del($variable);
  28. }
  29. }
  30. /**
  31. * Private helper to convert i18n_icon_* variables.
  32. *
  33. * @see languageicons_install()
  34. * @see languageicons_update_6000()
  35. */
  36. function _languageicons_convert_i18n_icon_variables() {
  37. $variables = array('path', 'size');
  38. foreach ($variables as $variable) {
  39. $old_variable = 'i18n_icon_' . $variable;
  40. $new_variable = 'languageicons_' . $variable;
  41. if (variable_get($new_variable) === NULL) {
  42. $old_variable_value = variable_get($old_variable, NULL);
  43. // If the standard path for flag icons was used, reset it.
  44. if ($variable == 'path') {
  45. $old_default_path = drupal_get_path('module', 'i18n') . '/flags/*.png';
  46. if ($old_variable_value == $old_default_path) {
  47. unset($old_variable_value, $old_default_path);
  48. }
  49. }
  50. if (!empty($old_variable_value)) {
  51. variable_set($new_variable, $old_variable_value);
  52. }
  53. }
  54. variable_del($old_variable);
  55. }
  56. }
  57. /**
  58. * Convert old "i18n_icon_*" variables.
  59. */
  60. function languageicons_update_6000() {
  61. _languageicons_convert_i18n_icon_variables();
  62. return t('Converted Internationalization (i18n) module settings to Language Icons settings.');
  63. }
  64. /**
  65. * Remove variable used for a short time during development of 6.x-2.x.
  66. *
  67. * @todo Remove this after the release of 7.x-1.0.
  68. */
  69. function languageicons_update_6200() {
  70. variable_del('languageicons_show_tooltip');
  71. return t('Removed site variable used during development of 6.x-2.x.');
  72. }