Commit 6be0aa47 authored by catch's avatar catch

Issue #1260510 by andypost, Berdir, Gábor Hojtsy: Introduce a language_load()($langcode).

parent 35b88bda
......@@ -32,7 +32,7 @@ function _locale_import_po($file, $langcode, $mode) {
drupal_set_time_limit(240);
// Check if we have the language already in the database.
if (!db_query("SELECT COUNT(language) FROM {languages} WHERE language = :language", array(':language' => $langcode))->fetchField()) {
if (!language_load($langcode)) {
drupal_set_message(t('The language selected for import is not supported.'), 'error');
return FALSE;
}
......
......@@ -764,8 +764,9 @@ function _locale_rebuild_js($langcode = NULL) {
// This is necessary to keep the variable consistent with the database
// version of the language and to prevent checking against an outdated hash.
$default_langcode = language_default()->language;
drupal_static_reset('language_list');
if ($default_langcode == $language->language) {
$default = db_query("SELECT * FROM {languages} WHERE language = :language", array(':language' => $default_langcode))->fetchObject();
$default = language_load($default_langcode);
variable_set('language_default', $default);
}
}
......
......@@ -239,22 +239,16 @@ function locale_languages_add_form($form, &$form_state) {
* @param $langcode
* Language code of the language to edit.
*/
function locale_languages_edit_form($form, &$form_state, $langcode) {
if ($language = db_query("SELECT * FROM {languages} WHERE language = :language", array(':language' => $langcode))->fetchObject()) {
_locale_languages_common_controls($form, $language);
$form['actions'] = array('#type' => 'actions');
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => t('Save language')
);
$form['#submit'][] = 'locale_languages_edit_form_submit';
$form['#validate'][] = 'locale_languages_edit_form_validate';
return $form;
}
else {
drupal_not_found();
drupal_exit();
}
function locale_languages_edit_form($form, &$form_state, $language) {
_locale_languages_common_controls($form, $language);
$form['actions'] = array('#type' => 'actions');
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => t('Save language')
);
$form['#submit'][] = 'locale_languages_edit_form_submit';
$form['#validate'][] = 'locale_languages_edit_form_validate';
return $form;
}
/**
......@@ -324,8 +318,7 @@ function locale_languages_add_predefined_form_validate($form, &$form_state) {
form_set_error('predefined_langcode', t('Fill in the language details and save the language with <em>Add custom language</em>.'));
}
else {
$languages = language_list();
if (isset($languages[$langcode])) {
if (language_load($langcode)) {
form_set_error('predefined_langcode', t('The language %language (%code) already exists.', array('%language' => $languages[$langcode]->name, '%code' => $langcode)));
}
}
......@@ -431,8 +424,8 @@ function locale_languages_edit_form_submit($form, &$form_state) {
/**
* User interface for the language deletion confirmation screen.
*/
function locale_languages_delete_form($form, &$form_state, $langcode) {
function locale_languages_delete_form($form, &$form_state, $language) {
$langcode = $language->language;
// Do not allow deletion of English locale.
if ($langcode == 'en') {
drupal_set_message(t('The English language cannot be deleted.'));
......
......@@ -125,14 +125,14 @@ function locale_menu() {
'file' => 'locale.admin.inc',
'type' => MENU_VISIBLE_IN_BREADCRUMB,
);
$items['admin/config/regional/language/edit/%'] = array(
$items['admin/config/regional/language/edit/%language'] = array(
'title' => 'Edit language',
'page callback' => 'drupal_get_form',
'page arguments' => array('locale_languages_edit_form', 5),
'access arguments' => array('administer languages'),
'file' => 'locale.admin.inc',
);
$items['admin/config/regional/language/delete/%'] = array(
$items['admin/config/regional/language/delete/%language'] = array(
'title' => 'Confirm',
'page callback' => 'drupal_get_form',
'page arguments' => array('locale_languages_delete_form', 5),
......@@ -255,6 +255,20 @@ function locale_permission() {
);
}
/**
* Loads a language object from the database.
*
* @param $langcode
* The language code.
*
* @return
* A fully-populated language object or FALSE.
*/
function language_load($langcode) {
$languages = language_list();
return isset($languages[$langcode]) ? $languages[$langcode] : FALSE;
}
/**
* Form builder callback to display language selection widget.
*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment