You are here

languageicons.install in Language Icons 6

Install, update, and uninstall functions for Language Icons.

File

languageicons.install
View source
<?php

/**
 * @file
 * Install, update, and uninstall functions for Language Icons.
 */

/**
 * Implementation of hook_install().
 */
function languageicons_install() {

  // Convert old "i18n_icon_*" variables, if any.
  _languageicons_convert_i18n_icon_variables();
}

/**
 * Implementation of hook_uninstall().
 */
function languageicons_uninstall() {

  // Clear any variables that might be in use
  $variables = array(
    'languageicons_show_node',
    'languageicons_show_block',
    'languageicons_placement',
    'languageicons_path',
    'languageicons_size',
  );
  foreach ($variables as $variable) {
    variable_del($variable);
  }
}

/**
 * Private helper to convert i18n_icon_* variables.
 *
 * @see languageicons_install()
 * @see languageicons_update_6000()
 */
function _languageicons_convert_i18n_icon_variables() {
  $variables = array(
    'path',
    'size',
  );
  foreach ($variables as $variable) {
    $old_variable = 'i18n_icon_' . $variable;
    $new_variable = 'languageicons_' . $variable;
    if (variable_get($new_variable, NULL) === NULL) {
      $old_variable_value = variable_get($old_variable, NULL);

      // If the standard path for flag icons was used, reset it.
      if ($variable == 'path') {
        $old_default_path = drupal_get_path('module', 'i18n') . '/flags/*.png';
        if ($old_variable_value == $old_default_path) {
          unset($old_variable_value, $old_default_path);
        }
      }
      if (!empty($old_variable_value)) {
        variable_set($new_variable, $old_variable_value);
      }
    }
    variable_del($old_variable);
  }
}

/**
 * Convert old "i18n_icon_*" variables.
 */
function languageicons_update_6000() {
  _languageicons_convert_i18n_icon_variables();
  return array();
}

Functions

Namesort descending Description
languageicons_install Implementation of hook_install().
languageicons_uninstall Implementation of hook_uninstall().
languageicons_update_6000 Convert old "i18n_icon_*" variables.
_languageicons_convert_i18n_icon_variables Private helper to convert i18n_icon_* variables.