Commit 5f0e0f36 authored by Steven Wittens's avatar Steven Wittens

- #33433: More form API fixes, and error handling improvements by Chx.

parent 09532828
This diff is collapsed.
......@@ -60,7 +60,7 @@ function _locale_admin_manage_screen() {
$ratio = ($original->strings > 0 && $translation->translation > 0) ? round(($translation->translation/$original->strings)*100., 2) : 0;
$form['name'][$key] = array('#type' => 'textfield', '#default_value' => $lang, '#size' => 15, '#maxlength' => 64);
$form['translation'][$key] = array('#type' => 'markup', '#default_value' => "$translation->translation/$original->strings ($ratio%)");
$form['translation'][$key] = array('#type' => 'markup', '#value' => "$translation->translation/$original->strings ($ratio%)");
}
}
$form['enabled'] = array('#type' => 'checkboxes', '#options' => $options, '#default_value' => $enabled, '#return_value' => 1);
......@@ -984,7 +984,7 @@ function _locale_string_edit($lid) {
: array('#type' => 'textfield', '#title' => $languages['name'][$translation->locale], '#default_value' => $translation->translation, '#size' => 60, '#maxlength' => 128);
unset($languages['name'][$translation->locale]);
}
$form = array('#type' => 'item', '#title' => t('Original text'), '#value' => wordwrap(check_plain($orig, 0)));
$form['item'] = array('#type' => 'item', '#title' => t('Original text'), '#value' => wordwrap(check_plain($orig, 0)));
foreach ($languages['name'] as $key => $lang) {
$form[$key] = (strlen($orig) > 40) ?
array('#type' => 'textarea', '#title' => $lang, '#cols' => 60, '#rows' => 15) :
......@@ -993,7 +993,7 @@ function _locale_string_edit($lid) {
$form['submit'] = array('#type' => 'submit', '#value' => t('Save translations'));
return $form;
return drupal_get_form('_locale_string_edit', $form);
}
/**
......
......@@ -108,7 +108,9 @@ function locale_user($type, $edit, &$user, $category = NULL) {
$user->language = key($languages['name']);
}
$languages['name'] = array_map('check_plain', $languages['name']);
return array(array('title' => t('Interface language settings'), 'data' => $form['locale_user'] = array('#type' => 'radios', '#title' => t('Language'), '#default_value' => $user->language, '#options' => $languages['name'], '#description' => t('Selecting a different locale will change the interface language of the site.'))));
$form['locale'] = array('#title' => t('Interface language settings'), '#type' => 'fieldset', '#weight' => 1);
$form['locale']['language'] = array('#type' => 'radios', '#title' => t('Language'), '#default_value' => $user->language, '#options' => $languages['name'], '#description' => t('Selecting a different locale will change the interface language of the site.'));
return $form;
}
}
......
......@@ -108,7 +108,9 @@ function locale_user($type, $edit, &$user, $category = NULL) {
$user->language = key($languages['name']);
}
$languages['name'] = array_map('check_plain', $languages['name']);
return array(array('title' => t('Interface language settings'), 'data' => $form['locale_user'] = array('#type' => 'radios', '#title' => t('Language'), '#default_value' => $user->language, '#options' => $languages['name'], '#description' => t('Selecting a different locale will change the interface language of the site.'))));
$form['locale'] = array('#title' => t('Interface language settings'), '#type' => 'fieldset', '#weight' => 1);
$form['locale']['language'] = array('#type' => 'radios', '#title' => t('Language'), '#default_value' => $user->language, '#options' => $languages['name'], '#description' => t('Selecting a different locale will change the interface language of the site.'));
return $form;
}
}
......
......@@ -1083,6 +1083,7 @@ function node_types_configure($type = NULL) {
$form['workflow'] = array('#type' => 'fieldset', '#title' =>t('Workflow'));
$form['workflow'] = array_merge($form['workflow'], node_invoke_nodeapi($node, 'settings'));
$form['array_filter'] = array('#type' => 'value', '#value' => TRUE);
return system_settings_form($type . '_node_settings', $form);
}
else {
......
......@@ -1083,6 +1083,7 @@ function node_types_configure($type = NULL) {
$form['workflow'] = array('#type' => 'fieldset', '#title' =>t('Workflow'));
$form['workflow'] = array_merge($form['workflow'], node_invoke_nodeapi($node, 'settings'));
$form['array_filter'] = array('#type' => 'value', '#value' => TRUE);
return system_settings_form($type . '_node_settings', $form);
}
else {
......
......@@ -298,7 +298,7 @@ function profile_view_profile($user) {
$description = ($field->visibility == PROFILE_PRIVATE) ? t('The content of this field is private and only visible to yourself.') : '';
$title = ($field->type != 'checkbox') ? check_plain($field->title) : '';
$form = array('#type' => 'item', '#title' => $title, '#value' => $value, '#description' => $description);
$fields[$field->category][$field->name] = form_render(_form_builder($form));
$fields[$field->category][$field->name] = drupal_get_form('profile_view_profile_' . $field->category .'_'. $field->name, $form, 'profile_view_profile');
}
}
......
......@@ -298,7 +298,7 @@ function profile_view_profile($user) {
$description = ($field->visibility == PROFILE_PRIVATE) ? t('The content of this field is private and only visible to yourself.') : '';
$title = ($field->type != 'checkbox') ? check_plain($field->title) : '';
$form = array('#type' => 'item', '#title' => $title, '#value' => $value, '#description' => $description);
$fields[$field->category][$field->name] = form_render(_form_builder($form));
$fields[$field->category][$field->name] = drupal_get_form('profile_view_profile_' . $field->category .'_'. $field->name, $form, 'profile_view_profile');
}
}
......
......@@ -188,7 +188,7 @@ function system_user($type, $edit, &$user, $category = NULL) {
$form['locale'] = array('#type'=>'item', '#title' => t('Locale settings'), '#weight' => 6);
$form['locale']['timezone'] = array(
'#type' => 'select', '#title' => t('Time zone'), '#default_value' => strlen($edit['timezone']) ? $edit['timezone'] : variable_get('date_default_timezone', 0),
'#options' => $zones, descriptions => t('Select your current local time. Dates and times throughout this site will be displayed using this time zone.')
'#options' => $zones, '#description' => t('Select your current local time. Dates and times throughout this site will be displayed using this time zone.')
);
}
return $form;
......@@ -684,7 +684,9 @@ function system_settings_form($form_id, $form) {
/**
* Execute the system_settings_form.
*
* Due to specific handling of checkboxes, this function does not handle 'tree' based forms.
* If you want node type configure style handling of your checkboxes,
* add an array_filter value to your form.
*
*/
function system_settings_form_execute($form_id, $values) {
$op = isset($_POST['op']) ? $_POST['op'] : '';
......@@ -694,7 +696,7 @@ function system_settings_form_execute($form_id, $values) {
variable_del($key);
}
else {
if (is_array($value)) {
if (is_array($value) && isset($values['array_filter'])) {
$value = array_keys(array_filter($value));
}
variable_set($key, $value);
......@@ -1057,11 +1059,14 @@ function system_theme_settings($key = '') {
$disabled['toggle_search'] = true;
}
$form['toggles'] = array('#type' => 'fieldset', '#title' => t('Toggle display'), '#description' => t('Enable or disable the display of certain page elements.'));
$form['theme_settings'] = array('#type' => 'fieldset', '#title' => t('Toggle display'), '#description' => t('Enable or disable the display of certain page elements.'), '#tree' => TRUE);
foreach ($toggles as $name => $title) {
if ((!$key) || in_array($name, $features)) {
// disable search box if search.module is disabled
$form['toggles'][$name] = array('#type' => 'checkbox', '#title' => $title, '#default_value' => $settings[$name], '#attributes' => isset($disabled[$name]) ? array('disabled' => 'disabled') : NULL);
$form['theme_settings'][$name] = array('#type' => 'checkbox', '#title' => $title, '#default_value' => $settings[$name]);
if (isset($disabled[$name])) {
$form['theme_settings'][$name]['#attributes'] = array('disabled' => 'disabled');
}
}
}
......
......@@ -188,7 +188,7 @@ function system_user($type, $edit, &$user, $category = NULL) {
$form['locale'] = array('#type'=>'item', '#title' => t('Locale settings'), '#weight' => 6);
$form['locale']['timezone'] = array(
'#type' => 'select', '#title' => t('Time zone'), '#default_value' => strlen($edit['timezone']) ? $edit['timezone'] : variable_get('date_default_timezone', 0),
'#options' => $zones, descriptions => t('Select your current local time. Dates and times throughout this site will be displayed using this time zone.')
'#options' => $zones, '#description' => t('Select your current local time. Dates and times throughout this site will be displayed using this time zone.')
);
}
return $form;
......@@ -684,7 +684,9 @@ function system_settings_form($form_id, $form) {
/**
* Execute the system_settings_form.
*
* Due to specific handling of checkboxes, this function does not handle 'tree' based forms.
* If you want node type configure style handling of your checkboxes,
* add an array_filter value to your form.
*
*/
function system_settings_form_execute($form_id, $values) {
$op = isset($_POST['op']) ? $_POST['op'] : '';
......@@ -694,7 +696,7 @@ function system_settings_form_execute($form_id, $values) {
variable_del($key);
}
else {
if (is_array($value)) {
if (is_array($value) && isset($values['array_filter'])) {
$value = array_keys(array_filter($value));
}
variable_set($key, $value);
......@@ -1057,11 +1059,14 @@ function system_theme_settings($key = '') {
$disabled['toggle_search'] = true;
}
$form['toggles'] = array('#type' => 'fieldset', '#title' => t('Toggle display'), '#description' => t('Enable or disable the display of certain page elements.'));
$form['theme_settings'] = array('#type' => 'fieldset', '#title' => t('Toggle display'), '#description' => t('Enable or disable the display of certain page elements.'), '#tree' => TRUE);
foreach ($toggles as $name => $title) {
if ((!$key) || in_array($name, $features)) {
// disable search box if search.module is disabled
$form['toggles'][$name] = array('#type' => 'checkbox', '#title' => $title, '#default_value' => $settings[$name], '#attributes' => isset($disabled[$name]) ? array('disabled' => 'disabled') : NULL);
$form['theme_settings'][$name] = array('#type' => 'checkbox', '#title' => $title, '#default_value' => $settings[$name]);
if (isset($disabled[$name])) {
$form['theme_settings'][$name]['#attributes'] = array('disabled' => 'disabled');
}
}
}
......
......@@ -476,7 +476,7 @@ function user_user($type, &$edit, &$user, $category = NULL) {
}
if ($type == 'validate' && $category == 'account') {
return user_edit_validate(arg(1), $edit);
return _user_edit_validate(arg(1), $edit);
}
if ($type == 'categories') {
......@@ -1172,7 +1172,7 @@ function user_edit_form($uid, $edit) {
return $form;
}
function user_edit_validate($uid, &$edit) {
function _user_edit_validate($uid, &$edit) {
// Validate the username:
if ($error = user_validate_name($edit['name'])) {
form_set_error('name', $error);
......
......@@ -476,7 +476,7 @@ function user_user($type, &$edit, &$user, $category = NULL) {
}
if ($type == 'validate' && $category == 'account') {
return user_edit_validate(arg(1), $edit);
return _user_edit_validate(arg(1), $edit);
}
if ($type == 'categories') {
......@@ -1172,7 +1172,7 @@ function user_edit_form($uid, $edit) {
return $form;
}
function user_edit_validate($uid, &$edit) {
function _user_edit_validate($uid, &$edit) {
// Validate the username:
if ($error = user_validate_name($edit['name'])) {
form_set_error('name', $error);
......
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