Commit e27e1a0e authored by Dries's avatar Dries

- Patch #266246 by sun, effulgentsia, marcingy: remove smart defaults for system_settings_form().

parent 218c363c
......@@ -34,7 +34,7 @@ function book_admin_settings() {
$form['book_allowed_types'] = array(
'#type' => 'checkboxes',
'#title' => t('Content types allowed in book outlines'),
'#default_value' => array('book'),
'#default_value' => variable_get('book_allowed_types', array('book')),
'#options' => $types,
'#description' => t('Users with the %outline-perm permission can add all content types.', array('%outline-perm' => t('Administer book outlines'))),
'#required' => TRUE,
......@@ -42,14 +42,14 @@ function book_admin_settings() {
$form['book_child_type'] = array(
'#type' => 'radios',
'#title' => t('Content type for child pages'),
'#default_value' => 'book',
'#default_value' => variable_get('book_child_type', 'book'),
'#options' => $types,
'#required' => TRUE,
);
$form['array_filter'] = array('#type' => 'value', '#value' => TRUE);
$form['#validate'][] = 'book_admin_settings_validate';
return system_settings_form($form, TRUE);
return system_settings_form($form);
}
/**
......
......@@ -210,25 +210,25 @@ function forum_admin_settings($form) {
$number = drupal_map_assoc(array(5, 10, 15, 20, 25, 30, 35, 40, 50, 60, 80, 100, 150, 200, 250, 300, 350, 400, 500));
$form['forum_hot_topic'] = array('#type' => 'select',
'#title' => t('Hot topic threshold'),
'#default_value' => 15,
'#default_value' => variable_get('forum_hot_topic', 15),
'#options' => $number,
'#description' => t('The number of replies a topic must have to be considered "hot".'),
);
$number = drupal_map_assoc(array(10, 25, 50, 75, 100));
$form['forum_per_page'] = array('#type' => 'select',
'#title' => t('Topics per page'),
'#default_value' => 25,
'#default_value' => variable_get('forum_per_page', 25),
'#options' => $number,
'#description' => t('Default number of forum topics displayed per page.'),
);
$forder = array(1 => t('Date - newest first'), 2 => t('Date - oldest first'), 3 => t('Posts - most active first'), 4 => t('Posts - least active first'));
$form['forum_order'] = array('#type' => 'radios',
'#title' => t('Default order'),
'#default_value' => '1',
'#default_value' => variable_get('forum_order', 1),
'#options' => $forder,
'#description' => t('Default display order for topics.'),
);
return system_settings_form($form, TRUE);
return system_settings_form($form);
}
/**
......
......@@ -693,8 +693,6 @@ function locale_languages_configure_form_submit($form, &$form_state) {
* The URL language provider configuration form.
*/
function locale_language_providers_url_form($form, &$form_state) {
$form = array();
$form['locale_language_negotiation_url_part'] = array(
'#title' => t('Part of the URL that determines language'),
'#type' => 'radios',
......@@ -715,8 +713,6 @@ function locale_language_providers_url_form($form, &$form_state) {
* The URL language provider configuration form.
*/
function locale_language_providers_session_form($form, &$form_state) {
$form = array();
$form['locale_language_negotiation_session_param'] = array(
'#title' => t('Request/session parameter'),
'#type' => 'textfield',
......
......@@ -684,7 +684,7 @@ function menu_configure() {
$form['menu_main_links_source'] = array(
'#type' => 'select',
'#title' => t('Source for the Main links'),
'#default_value' => 'main-menu',
'#default_value' => variable_get('menu_main_links_source', 'main-menu'),
'#options' => $main_options,
'#tree' => FALSE,
'#description' => t('Select what should be displayed as the Main links (typically at the top of the page).'),
......@@ -694,11 +694,11 @@ function menu_configure() {
$form['menu_secondary_links_source'] = array(
'#type' => 'select',
'#title' => t('Source for the Secondary links'),
'#default_value' => 'user-menu',
'#default_value' => variable_get('menu_secondary_links_source', 'user-menu'),
'#options' => $secondary_options,
'#tree' => FALSE,
'#description' => t("Select the source for the Secondary links. An advanced option allows you to use the same source for both Main links (currently %main) and Secondary links: if your source menu has two levels of hierarchy, the top level menu links will appear in the Main links, and the children of the active link will appear in the Secondary links." , array('%main' => $main_options[$main])),
);
return system_settings_form($form, TRUE);
return system_settings_form($form);
}
......@@ -83,7 +83,7 @@ function search_admin_settings($form) {
$form['indexing_throttle']['search_cron_limit'] = array(
'#type' => 'select',
'#title' => t('Number of items to index per cron run'),
'#default_value' => 100,
'#default_value' => variable_get('search_cron_limit', 100),
'#options' => $items,
'#description' => t('The maximum number of items indexed in each pass of a <a href="@cron">cron maintenance task</a>. If necessary, reduce the number of items to prevent timeouts and memory errors while indexing.', array('@cron' => url('admin/reports/status')))
);
......@@ -98,7 +98,7 @@ function search_admin_settings($form) {
$form['indexing_settings']['minimum_word_size'] = array(
'#type' => 'textfield',
'#title' => t('Minimum word length to index'),
'#default_value' => 3,
'#default_value' => variable_get('minimum_word_size', 3),
'#size' => 5,
'#maxlength' => 3,
'#description' => t('The number of characters a word has to be to be indexed. A lower setting means better search result ranking, but also a larger database. Each search query must contain at least one keyword that is this size (or longer).')
......@@ -106,7 +106,7 @@ function search_admin_settings($form) {
$form['indexing_settings']['overlap_cjk'] = array(
'#type' => 'checkbox',
'#title' => t('Simple CJK handling'),
'#default_value' => TRUE,
'#default_value' => variable_get('overlap_cjk', TRUE),
'#description' => t('Whether to apply a simple Chinese/Japanese/Korean tokenizer based on overlapping sequences. Turn this off if you want to use an external preprocessor for this instead. Does not affect other languages.')
);
......@@ -116,7 +116,7 @@ function search_admin_settings($form) {
);
$form['active']['search_active_modules'] = array(
'#type' => 'checkboxes',
'#default_value' => array('node', 'user'),
'#default_value' => variable_get('search_active_modules', array('node', 'user')),
'#options' => _search_get_module_names(),
'#description' => t('Determine which search modules are active from the available modules.')
);
......@@ -131,7 +131,7 @@ function search_admin_settings($form) {
}
}
return system_settings_form($form, TRUE);
return system_settings_form($form);
}
/**
......
......@@ -248,13 +248,13 @@ function statistics_settings_form() {
$form['access']['statistics_enable_access_log'] = array(
'#type' => 'checkbox',
'#title' => t('Enable access log'),
'#default_value' => 0,
'#default_value' => variable_get('statistics_enable_access_log', 0),
'#description' => t('Log each page access. Required for referrer statistics.'),
);
$form['access']['statistics_flush_accesslog_timer'] = array(
'#type' => 'select',
'#title' => t('Discard access logs older than'),
'#default_value' => 259200,
'#default_value' => variable_get('statistics_flush_accesslog_timer', 259200),
'#options' => array(0 => t('Never')) + drupal_map_assoc(array(3600, 10800, 21600, 32400, 43200, 86400, 172800, 259200, 604800, 1209600, 2419200, 4838400, 9676800), 'format_interval'),
'#description' => t('Older access log entries (including referrer statistics) will be automatically discarded. (Requires a correctly configured <a href="@cron">cron maintenance task</a>.)', array('@cron' => url('admin/reports/status'))),
);
......@@ -267,7 +267,7 @@ function statistics_settings_form() {
$form['content']['statistics_count_content_views'] = array(
'#type' => 'checkbox',
'#title' => t('Count content views'),
'#default_value' => 0,
'#default_value' => variable_get('statistics_count_content_views', 0),
'#description' => t('Increment a counter each time content is viewed.'),
);
......
......@@ -643,7 +643,7 @@ function system_theme_settings($form, &$form_state, $key = '') {
}
}
$form = system_settings_form($form, FALSE);
$form = system_settings_form($form);
// We don't want to call system_settings_form_submit(), so change #submit.
array_pop($form['#submit']);
$form['#submit'][] = 'system_theme_settings_submit';
......@@ -1567,7 +1567,7 @@ function system_site_information_settings() {
$form['#validate'][] = 'system_site_information_settings_validate';
return system_settings_form($form, FALSE);
return system_settings_form($form);
}
/**
......@@ -1596,7 +1596,7 @@ function system_logging_settings() {
$form['error_level'] = array(
'#type' => 'radios',
'#title' => t('Error messages to display'),
'#default_value' => ERROR_REPORTING_DISPLAY_ALL,
'#default_value' => variable_get('error_level', ERROR_REPORTING_DISPLAY_ALL),
'#options' => array(
ERROR_REPORTING_HIDE => t('None'),
ERROR_REPORTING_DISPLAY_SOME => t('Errors and warnings'),
......@@ -1695,7 +1695,7 @@ function system_performance_settings() {
$form['#submit'][] = 'drupal_clear_css_cache';
$form['#submit'][] = 'drupal_clear_js_cache';
return system_settings_form($form, FALSE);
return system_settings_form($form);
}
/**
......@@ -1715,11 +1715,10 @@ function system_clear_cache_submit($form, &$form_state) {
* @see system_settings_form()
*/
function system_file_system_settings() {
$form['file_public_path'] = array(
'#type' => 'textfield',
'#title' => t('Public file system path'),
'#default_value' => file_directory_path(),
'#default_value' => variable_get('file_public_path', file_directory_path()),
'#maxlength' => 255,
'#description' => t('A local file system path where public files will be stored. This directory must exist and be writable by Drupal. This directory must be relative to the Drupal installation directory and be accessible over the web.'),
'#after_build' => array('system_check_directory'),
......@@ -1728,7 +1727,7 @@ function system_file_system_settings() {
$form['file_private_path'] = array(
'#type' => 'textfield',
'#title' => t('Private file system path'),
'#default_value' => file_directory_path('private'),
'#default_value' => variable_get('file_private_path', file_directory_path('private')),
'#maxlength' => 255,
'#description' => t('A local file system path where private files will be stored. This directory must exist and be writable by Drupal. This directory should not be accessible over the web.'),
'#after_build' => array('system_check_directory'),
......@@ -1737,7 +1736,7 @@ function system_file_system_settings() {
$form['file_temporary_path'] = array(
'#type' => 'textfield',
'#title' => t('Temporary directory'),
'#default_value' => file_directory_path('temporary'),
'#default_value' => variable_get('file_temporary_path', file_directory_path('temporary')),
'#maxlength' => 255,
'#description' => t('A local file system path where temporary files will be stored. This directory should not be accessible over the web.'),
'#after_build' => array('system_check_directory'),
......@@ -1752,13 +1751,13 @@ function system_file_system_settings() {
$form['file_default_scheme'] = array(
'#type' => 'radios',
'#title' => t('Default download method'),
'#default_value' => isset($options['public']) ? 'public' : key($options),
'#default_value' => variable_get('file_default_scheme', isset($options['public']) ? 'public' : key($options)),
'#options' => $options,
'#description' => t('This setting is used as the preferred download method. The use of public files is more efficient, but does not provide any access control.'),
);
}
return system_settings_form($form, TRUE);
return system_settings_form($form);
}
/**
......@@ -1783,7 +1782,7 @@ function system_image_toolkit_settings() {
$form['image_toolkit'] = array(
'#type' => 'radios',
'#title' => t('Select an image processing toolkit'),
'#default_value' => $current_toolkit,
'#default_value' => variable_get('image_toolkit', $current_toolkit),
'#options' => $toolkits_available
);
}
......@@ -1797,7 +1796,7 @@ function system_image_toolkit_settings() {
$form['image_toolkit_settings'] = $function();
}
return system_settings_form($form, TRUE);
return system_settings_form($form);
}
/**
......@@ -1807,29 +1806,28 @@ function system_image_toolkit_settings() {
* @see system_settings_form()
*/
function system_rss_feeds_settings() {
$form['feed_description'] = array(
'#type' => 'textarea',
'#title' => t('Feed description'),
'#default_value' => '',
'#default_value' => variable_get('feed_description', ''),
'#description' => t('Description of your site, included in each feed.')
);
$form['feed_default_items'] = array(
'#type' => 'select',
'#title' => t('Number of items in each feed'),
'#default_value' => 10,
'#default_value' => variable_get('feed_default_items', 10),
'#options' => drupal_map_assoc(array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 25, 30)),
'#description' => t('Default number of items to include in each feed.')
);
$form['feed_item_length'] = array(
'#type' => 'select',
'#title' => t('Feed content'),
'#default_value' => 'fulltext',
'#default_value' => variable_get('feed_item_length', 'fulltext'),
'#options' => array('title' => t('Titles only'), 'teaser' => t('Titles plus teaser'), 'fulltext' => t('Full text')),
'#description' => t('Global setting for the default display of content items in each feed.')
);
return system_settings_form($form, TRUE);
return system_settings_form($form);
}
/**
......@@ -1916,7 +1914,7 @@ function system_regional_settings() {
'#description' => t('Only applied if users may set their own time zone.')
);
return system_settings_form($form, FALSE);
return system_settings_form($form);
}
/**
......@@ -1991,7 +1989,7 @@ function system_date_time_settings() {
// Display a message if no date types configured.
$form['#empty_text'] = t('No date types available. <a href="@link">Add date type</a>.', array('@link' => url('admin/config/regional/date-time/types/add')));
return system_settings_form($form, FALSE);
return system_settings_form($form);
}
/**
......@@ -2152,17 +2150,17 @@ function system_site_maintenance_mode() {
$form['maintenance_mode'] = array(
'#type' => 'checkbox',
'#title' => t('Put site into maintenance mode'),
'#default_value' => 0,
'#default_value' => variable_get('maintenance_mode', 0),
'#description' => t('When enabled, only users with the "Access site in maintenance mode" <a href="@permissions-url">permission</a> are able to access your site to perform maintenance; all other visitors see the maintenance mode message configured below. Authorized users can log in directly via the <a href="@user-login">user login</a> page.', array('@permissions-url' => url('admin/people/permissions'), '@user-login' => url('user'))),
);
$form['maintenance_mode_message'] = array(
'#type' => 'textarea',
'#title' => t('Maintenance mode message'),
'#default_value' => t('@site is currently under maintenance. We should be back shortly. Thank you for your patience.', array('@site' => variable_get('site_name', 'Drupal'))),
'#default_value' => variable_get('maintenance_mode_message', t('@site is currently under maintenance. We should be back shortly. Thank you for your patience.', array('@site' => variable_get('site_name', 'Drupal')))),
'#description' => t('Message to show visitors when the site is in maintenance mode.')
);
return system_settings_form($form, TRUE);
return system_settings_form($form);
}
/**
......@@ -2193,7 +2191,7 @@ function system_clean_url_settings($form, &$form_state) {
$form['clean_url'] = array(
'#type' => 'checkbox',
'#title' => t('Enable clean URLs'),
'#default_value' => 0,
'#default_value' => variable_get('clean_url', 0),
'#description' => t('Use URLs like <code>example.com/user</code> instead of <code>example.com/?q=user</code>.'),
);
$form = system_settings_form($form);
......
......@@ -2573,32 +2573,11 @@ function system_default_region($theme) {
return isset($regions[0]) ? $regions[0] : '';
}
function _system_settings_form_automatic_defaults($form) {
// Get an array of all non-property keys
$keys = element_children($form);
foreach ($keys as $key) {
// If the property (key) '#default_value' exists, replace it.
if (array_key_exists('#default_value', $form[$key])) {
$form[$key]['#default_value'] = variable_get($key, $form[$key]['#default_value']);
}
else {
// Recurse through child elements
$form[$key] = _system_settings_form_automatic_defaults($form[$key]);
}
}
return $form;
}
/**
* Add default buttons to a form and set its prefix.
*
* @param $form
* An associative array containing the structure of the form.
* @param $automatic_defaults
* Automatically load the saved values for each field from the system variables
* (defaults to TRUE).
*
* @return
* The form structure.
......@@ -2606,14 +2585,10 @@ function _system_settings_form_automatic_defaults($form) {
* @see system_settings_form_submit()
* @ingroup forms
*/
function system_settings_form($form, $automatic_defaults = TRUE) {
function system_settings_form($form) {
$form['actions']['#type'] = 'actions';
$form['actions']['submit'] = array('#type' => 'submit', '#value' => t('Save configuration'));
if ($automatic_defaults) {
$form = _system_settings_form_automatic_defaults($form);
}
if (!empty($_POST) && form_get_errors()) {
drupal_set_message(t('The settings have not been saved because of the errors.'), 'error');
}
......
......@@ -1226,83 +1226,6 @@ class SystemMainContentFallback extends DrupalWebTestCase {
}
}
class SystemSettingsForm extends DrupalWebTestCase {
/**
* Implement getInfo().
*/
public static function getInfo() {
return array(
'name' => 'System setting forms',
'description' => 'Tests correctness of system_settings_form() processing.',
'group' => 'System'
);
}
/**
* Implement setUp().
*/
function setUp() {
parent::setUp();
variable_set('system_settings_form_test', TRUE);
variable_set('system_settings_form_test_4', TRUE);
}
/**
* Reset page title.
*/
function tearDown() {
variable_del('system_settings_form_test');
variable_del('system_settings_form_test_4');
parent::tearDown();
}
/**
* Tests the handling of automatic defaults in systems_settings_form().
*/
function testAutomaticDefaults() {
$form['system_settings_form_test'] = array(
'#type' => 'checkbox',
'#default_value' => FALSE,
);
$form['system_settings_form_test_2'] = array(
'#type' => 'checkbox',
'#default_value' => FALSE,
);
$form['system_settings_form_test_3'] = array(
'#type' => 'checkbox',
'#default_value' => TRUE,
);
$form['has_children']['system_settings_form_test_4'] = array(
'#type' => 'checkbox',
'#default_value' => FALSE,
);
$form['has_children']['system_settings_form_test_5'] = array(
'#type' => 'checkbox',
'#default_value' => TRUE,
);
$automatic = system_settings_form($form, FALSE);
$this->assertFalse($automatic['system_settings_form_test']['#default_value']);
$this->assertFalse($automatic['system_settings_form_test_2']['#default_value']);
$this->assertTrue($automatic['system_settings_form_test_3']['#default_value']);
$this->assertFalse($automatic['has_children']['system_settings_form_test_4']['#default_value']);
$this->assertTrue($automatic['has_children']['system_settings_form_test_5']['#default_value']);
$no_automatic = system_settings_form($form);
$this->assertTrue($no_automatic['system_settings_form_test']['#default_value']);
$this->assertFalse($no_automatic['system_settings_form_test_2']['#default_value']);
$this->assertTrue($no_automatic['system_settings_form_test_3']['#default_value']);
$this->assertTrue($no_automatic['has_children']['system_settings_form_test_4']['#default_value']);
$this->assertTrue($no_automatic['has_children']['system_settings_form_test_5']['#default_value']);
}
}
/**
* Tests for the theme interface functionality.
*/
......
......@@ -47,7 +47,7 @@ function update_settings($form) {
'#description' => t('You can choose to send e-mail only if a security update is available, or to be notified about all newer versions. If there are updates available of Drupal core or any of your installed modules and themes, your site will always print a message on the <a href="@status_report">status report</a> page, and will also display an error message on administration pages if there is a security update.', array('@status_report' => url('admin/reports/status')))
);
$form = system_settings_form($form, FALSE);
$form = system_settings_form($form);
// Custom validation callback for the email notification setting.
$form['#validate'][] = 'update_settings_validate';
// We need to call our own submit callback first, not the one from
......
......@@ -635,7 +635,7 @@ function user_admin_settings() {
'#rows' => 3,
);
return system_settings_form($form, FALSE);
return system_settings_form($form);
}
/**
......
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