Commit 702c0a2b authored by Gábor Hojtsy's avatar Gábor Hojtsy
Browse files

#190283 by myself and JirkaRbyka: use get_t() in pre-database setup code, add...

#190283 by myself and JirkaRbyka: use get_t() in pre-database setup code, add missing javascript key to language objects (kills notices) and document st() better
parent aa5b27d8
...@@ -1083,7 +1083,7 @@ function language_list($field = 'language', $reset = FALSE) { ...@@ -1083,7 +1083,7 @@ function language_list($field = 'language', $reset = FALSE) {
* Optional property of the language object to return * Optional property of the language object to return
*/ */
function language_default($property = NULL) { function language_default($property = NULL) {
$language = variable_get('language_default', (object) array('language' => 'en', 'name' => 'English', 'native' => 'English', 'direction' => 0, 'enabled' => 1, 'plurals' => 0, 'formula' => '', 'domain' => '', 'prefix' => '', 'weight' => 0)); $language = variable_get('language_default', (object) array('language' => 'en', 'name' => 'English', 'native' => 'English', 'direction' => 0, 'enabled' => 1, 'plurals' => 0, 'formula' => '', 'domain' => '', 'prefix' => '', 'weight' => 0, 'javascript' => ''));
return $property ? $language->$property : $language; return $property ? $language->$property : $language;
} }
......
...@@ -565,6 +565,9 @@ function drupal_redirect_form($form, $redirect = NULL) { ...@@ -565,6 +565,9 @@ function drupal_redirect_form($form, $redirect = NULL) {
* theming, and hook_form_alter functions. * theming, and hook_form_alter functions.
*/ */
function _form_validate($elements, &$form_state, $form_id = NULL) { function _form_validate($elements, &$form_state, $form_id = NULL) {
// Also used in the installer, pre-database setup.
$t = get_t();
// Recurse through all children. // Recurse through all children.
foreach (element_children($elements) as $key) { foreach (element_children($elements) as $key) {
if (isset($elements[$key]) && $elements[$key]) { if (isset($elements[$key]) && $elements[$key]) {
...@@ -578,12 +581,12 @@ function _form_validate($elements, &$form_state, $form_id = NULL) { ...@@ -578,12 +581,12 @@ function _form_validate($elements, &$form_state, $form_id = NULL) {
// and a textfield could return '0' and empty('0') returns TRUE so we // and a textfield could return '0' and empty('0') returns TRUE so we
// need a special check for the '0' string. // need a special check for the '0' string.
if ($elements['#required'] && empty($elements['#value']) && $elements['#value'] !== '0') { if ($elements['#required'] && empty($elements['#value']) && $elements['#value'] !== '0') {
form_error($elements, t('!name field is required.', array('!name' => $elements['#title']))); form_error($elements, $t('!name field is required.', array('!name' => $elements['#title'])));
} }
// Verify that the value is not longer than #maxlength. // Verify that the value is not longer than #maxlength.
if (isset($elements['#maxlength']) && drupal_strlen($elements['#value']) > $elements['#maxlength']) { if (isset($elements['#maxlength']) && drupal_strlen($elements['#value']) > $elements['#maxlength']) {
form_error($elements, t('!name cannot be longer than %max characters but is currently %length characters long.', array('!name' => empty($elements['#title']) ? $elements['#parents'][0] : $elements['#title'], '%max' => $elements['#maxlength'], '%length' => drupal_strlen($elements['#value'])))); form_error($elements, $t('!name cannot be longer than %max characters but is currently %length characters long.', array('!name' => empty($elements['#title']) ? $elements['#parents'][0] : $elements['#title'], '%max' => $elements['#maxlength'], '%length' => drupal_strlen($elements['#value']))));
} }
if (isset($elements['#options']) && isset($elements['#value'])) { if (isset($elements['#options']) && isset($elements['#value'])) {
...@@ -597,13 +600,13 @@ function _form_validate($elements, &$form_state, $form_id = NULL) { ...@@ -597,13 +600,13 @@ function _form_validate($elements, &$form_state, $form_id = NULL) {
$value = $elements['#type'] == 'checkboxes' ? array_keys(array_filter($elements['#value'])) : $elements['#value']; $value = $elements['#type'] == 'checkboxes' ? array_keys(array_filter($elements['#value'])) : $elements['#value'];
foreach ($value as $v) { foreach ($value as $v) {
if (!isset($options[$v])) { if (!isset($options[$v])) {
form_error($elements, t('An illegal choice has been detected. Please contact the site administrator.')); form_error($elements, $t('An illegal choice has been detected. Please contact the site administrator.'));
watchdog('form', 'Illegal choice %choice in !name element.', array('%choice' => $v, '!name' => empty($elements['#title']) ? $elements['#parents'][0] : $elements['#title']), WATCHDOG_ERROR); watchdog('form', 'Illegal choice %choice in !name element.', array('%choice' => $v, '!name' => empty($elements['#title']) ? $elements['#parents'][0] : $elements['#title']), WATCHDOG_ERROR);
} }
} }
} }
elseif (!isset($options[$elements['#value']])) { elseif (!isset($options[$elements['#value']])) {
form_error($elements, t('An illegal choice has been detected. Please contact the site administrator.')); form_error($elements, $t('An illegal choice has been detected. Please contact the site administrator.'));
watchdog('form', 'Illegal choice %choice in %name element.', array('%choice' => $elements['#value'], '%name' => empty($elements['#title']) ? $elements['#parents'][0] : $elements['#title']), WATCHDOG_ERROR); watchdog('form', 'Illegal choice %choice in %name element.', array('%choice' => $elements['#value'], '%name' => empty($elements['#title']) ? $elements['#parents'][0] : $elements['#title']), WATCHDOG_ERROR);
} }
} }
...@@ -1969,20 +1972,23 @@ function theme_file($element) { ...@@ -1969,20 +1972,23 @@ function theme_file($element) {
* A string representing the form element. * A string representing the form element.
*/ */
function theme_form_element($element, $value) { function theme_form_element($element, $value) {
// This is also used in the installer, pre-database setup.
$t = get_t();
$output = '<div class="form-item"'; $output = '<div class="form-item"';
if (!empty($element['#id'])) { if (!empty($element['#id'])) {
$output .= ' id="'. $element['#id'] .'-wrapper"'; $output .= ' id="'. $element['#id'] .'-wrapper"';
} }
$output .= ">\n"; $output .= ">\n";
$required = !empty($element['#required']) ? '<span class="form-required" title="'. t('This field is required.') .'">*</span>' : ''; $required = !empty($element['#required']) ? '<span class="form-required" title="'. $t('This field is required.') .'">*</span>' : '';
if (!empty($element['#title'])) { if (!empty($element['#title'])) {
$title = $element['#title']; $title = $element['#title'];
if (!empty($element['#id'])) { if (!empty($element['#id'])) {
$output .= ' <label for="'. $element['#id'] .'">'. t('!title: !required', array('!title' => $title, '!required' => $required)) ."</label>\n"; $output .= ' <label for="'. $element['#id'] .'">'. $t('!title: !required', array('!title' => $title, '!required' => $required)) ."</label>\n";
} }
else { else {
$output .= ' <label>'. t('!title: !required', array('!title' => $title, '!required' => $required)) ."</label>\n"; $output .= ' <label>'. $t('!title: !required', array('!title' => $title, '!required' => $required)) ."</label>\n";
} }
} }
......
...@@ -595,8 +595,9 @@ function install_goto($path) { ...@@ -595,8 +595,9 @@ function install_goto($path) {
} }
/** /**
* Hardcoded function for doing the equivalent of theme('placeholder') * Hardcoded function for doing the equivalent of t() during
* when the theme system is not available. * the install process, when database, theme, and localization
* system is possibly not yet available.
*/ */
function st($string, $args = array()) { function st($string, $args = array()) {
static $locale_strings = NULL; static $locale_strings = NULL;
......
...@@ -917,7 +917,7 @@ function locale_add_language($langcode, $name = NULL, $native = NULL, $direction ...@@ -917,7 +917,7 @@ function locale_add_language($langcode, $name = NULL, $native = NULL, $direction
// Only set it as default if enabled. // Only set it as default if enabled.
if ($enabled && $default) { if ($enabled && $default) {
variable_set('language_default', (object) array('language' => $langcode, 'name' => $name, 'native' => $native, 'direction' => $direction, 'enabled' => (int) $enabled, 'plurals' => 0, 'formula' => '', 'domain' => '', 'prefix' => $prefix, 'weight' => 0)); variable_set('language_default', (object) array('language' => $langcode, 'name' => $name, 'native' => $native, 'direction' => $direction, 'enabled' => (int) $enabled, 'plurals' => 0, 'formula' => '', 'domain' => '', 'prefix' => $prefix, 'weight' => 0, 'javascript' => ''));
} }
if ($enabled) { if ($enabled) {
......
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