diff options
author | Dries Buytaert <dries@buytaert.net> | 2010-06-26 21:32:20 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2010-06-26 21:32:20 +0000 |
commit | e27e1a0e0df1e070d8172921461b815317f4bfaa (patch) | |
tree | 4136c973a3c66295ce8e4a6853e08faf7111283f /modules/system | |
parent | 218c363c5a79fdfe5c0d8867f0f1c0c4b973a724 (diff) | |
download | brdo-e27e1a0e0df1e070d8172921461b815317f4bfaa.tar.gz brdo-e27e1a0e0df1e070d8172921461b815317f4bfaa.tar.bz2 |
- Patch #266246 by sun, effulgentsia, marcingy: remove smart defaults for system_settings_form().
Diffstat (limited to 'modules/system')
-rw-r--r-- | modules/system/system.admin.inc | 44 | ||||
-rw-r--r-- | modules/system/system.module | 27 | ||||
-rw-r--r-- | modules/system/system.test | 77 |
3 files changed, 22 insertions, 126 deletions
diff --git a/modules/system/system.admin.inc b/modules/system/system.admin.inc index 152d2982c..6323db0fa 100644 --- a/modules/system/system.admin.inc +++ b/modules/system/system.admin.inc @@ -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); diff --git a/modules/system/system.module b/modules/system/system.module index d187cc4ce..7ebd8004b 100644 --- a/modules/system/system.module +++ b/modules/system/system.module @@ -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'); } diff --git a/modules/system/system.test b/modules/system/system.test index f1a4407a7..b2da62566 100644 --- a/modules/system/system.test +++ b/modules/system/system.test @@ -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. */ |