You are here

function locale_update_6005 in Drupal 6

Change language setting variable of content types.

Use language_content_type_<content_type> instead of language_<content_type> so content types such as 'default', 'count' or 'negotiation' will not interfere with language variables.

Related topics

File

modules/locale/locale.install, line 171

Code

function locale_update_6005() {
  foreach (node_get_types() as $type => $content_type) {

    // Default to NULL, so we can skip dealing with non-existent settings.
    $setting = variable_get('language_' . $type, NULL);
    if ($type == 'default' && is_numeric($setting)) {

      // language_default was overwritten with the content type setting,
      // so reset the default language and save the content type setting.
      variable_set('language_content_type_default', $setting);
      variable_del('language_default');
      drupal_set_message('The default language setting has been reset to its default value. Check the ' . l('language configuration page', 'admin/settings/language') . ' to configure it correctly.');
    }
    elseif ($type == 'negotiation') {

      // language_content_type_negotiation is an integer either if it is
      // the negotiation setting or the content type setting.
      // The language_negotiation setting is not reset, but
      // the user is alerted that this setting possibly was overwritten
      variable_set('language_content_type_negotiation', $setting);
      drupal_set_message('The language negotiation setting was possibly overwritten by a content type of the same name. Check the ' . l('language configuration page', 'admin/settings/language/configure') . ' and the ' . l('<em>' . $content_type->name . "</em> content type's multilingual support settings", 'admin/content/types/negotiation', array(
        'html' => TRUE,
      )) . ' to configure them correctly.');
    }
    elseif (!is_null($setting)) {

      // Change the language setting variable for any other content type.
      // Do not worry about language_count, it will be updated below.
      variable_set('language_content_type_' . $type, $setting);
      variable_del('language_' . $type);
    }
  }

  // Update language count variable that might be overwritten.
  $count = db_result(db_query('SELECT COUNT(*) FROM {languages} WHERE enabled = 1'));
  variable_set('language_count', $count);
  return array();
}