diff --git a/core/includes/form.inc b/core/includes/form.inc index ac789e1..be5324a 100644 --- a/core/includes/form.inc +++ b/core/includes/form.inc @@ -2005,6 +2005,10 @@ function _form_builder_handle_input_element($form_id, &$element, &$form_state) { // submitted with drupal_form_submit() may bypass access restriction and be // treated as high-privilege users instead. $process_input = empty($element['#disabled']) && ($form_state['programmed'] || ($form_state['process_input'] && (!isset($element['#access']) || $element['#access']))); + $loadable = isset($element['#load']) && isset($form_state['callbacks']['load'][$element['#load']]); + if ($loadable) { + $form_state['loadables'][$element['#load']][] = $element['#array_parents']; + } // Set the element's #value property. if (!isset($element['#value']) && !array_key_exists('#value', $element)) { @@ -2046,6 +2050,10 @@ function _form_builder_handle_input_element($form_id, &$element, &$form_state) { } // Load defaults. if (!isset($element['#value'])) { + if ($loadable) { + $function = $form_state['callbacks']['load'][$element['#load']]; + $element['#default_value'] = $function($element); + } // Call #type_value without a second argument to request default_value handling. if (function_exists($value_callback)) { $element['#value'] = $value_callback($element, FALSE, $form_state); diff --git a/core/modules/aggregator/aggregator.admin.inc b/core/modules/aggregator/aggregator.admin.inc index 718e79c..8830be4 100644 --- a/core/modules/aggregator/aggregator.admin.inc +++ b/core/modules/aggregator/aggregator.admin.inc @@ -428,14 +428,17 @@ function aggregator_admin_refresh_feed($feed) { * @see aggregator_admin_form_submit() * @ingroup forms */ -function aggregator_admin_form($form, $form_state) { +function aggregator_admin_form($form, &$form_state) { + $form['#config'] = config('aggregator.settings'); + // Global aggregator settings. $form['aggregator_allowed_html_tags'] = array( '#type' => 'textfield', '#title' => t('Allowed HTML tags'), '#size' => 80, '#maxlength' => 255, - '#default_value' => config('aggregator.settings')->get('items.allowed_html'), + '#load' => 'config', + '#config_key' => 'items.allowed_html', '#description' => t('A space-separated list of HTML tags allowed in the content of feed items. Disallowed tags are stripped from the content.'), ); @@ -484,7 +487,8 @@ function aggregator_admin_form($form, $form_state) { '#title' => t('Fetcher'), '#description' => t('Fetchers download data from an external source. Choose a fetcher suitable for the external source you would like to download from.'), '#options' => $fetchers, - '#default_value' => config('aggregator.settings')->get('fetcher'), + '#load' => 'config', + '#config_key' => 'fetcher', ); } if (count($parsers) > 1) { @@ -493,7 +497,8 @@ function aggregator_admin_form($form, $form_state) { '#title' => t('Parser'), '#description' => t('Parsers transform downloaded data into standard structures. Choose a parser suitable for the type of feeds you would like to aggregate.'), '#options' => $parsers, - '#default_value' => config('aggregator.settings')->get('parser'), + '#load' => 'config', + '#config_key' => 'parser', ); } if (count($processors) > 1) { @@ -502,7 +507,8 @@ function aggregator_admin_form($form, $form_state) { '#title' => t('Processors'), '#description' => t('Processors act on parsed feed data, for example they store feed items. Choose the processors suitable for your task.'), '#options' => $processors, - '#default_value' => config('aggregator.settings')->get('processors'), + '#load' => 'config', + '#config_key' => 'processors', ); } if (count($basic_conf)) { @@ -523,30 +529,6 @@ function aggregator_admin_form($form, $form_state) { } /** - * Form submission handler for aggregator_admin_form(). - */ -function aggregator_admin_form_submit($form, &$form_state) { - $config = config('aggregator.settings'); - $config - ->set('items.allowed_html', $form_state['values']['aggregator_allowed_html_tags']) - ->set('items.expire', $form_state['values']['aggregator_clear']) - ->set('items.teaser_length', $form_state['values']['aggregator_teaser_length']) - ->set('source.list_max', $form_state['values']['aggregator_summary_items']) - ->set('source.category_selector', $form_state['values']['aggregator_category_selector']); - - if (isset($form_state['values']['aggregator_fetcher'])) { - $config->set('fetcher', $form_state['values']['aggregator_fetcher']); - } - if (isset($form_state['values']['aggregator_parser'])) { - $config->set('parser', $form_state['values']['aggregator_parser']); - } - if (isset($form_state['values']['aggregator_processors'])) { - $config->set('processors', array_filter($form_state['values']['aggregator_processors'])); - } - $config->save(); -} - -/** * Form constructor to add/edit/delete aggregator categories. * * @param $edit diff --git a/core/modules/aggregator/aggregator.processor.inc b/core/modules/aggregator/aggregator.processor.inc index c12c90f..9a42dc0 100644 --- a/core/modules/aggregator/aggregator.processor.inc +++ b/core/modules/aggregator/aggregator.processor.inc @@ -70,8 +70,7 @@ function aggregator_aggregator_remove($feed) { * separate from aggregator API functionality. */ function aggregator_form_aggregator_admin_form_alter(&$form, $form_state) { - $config = config('aggregator.settings'); - $aggregator_processors = $config->get('processors'); + $aggregator_processors = $form['#config']->get('processors'); if (in_array('aggregator', $aggregator_processors)) { $info = module_invoke('aggregator', 'aggregator_process', 'info'); $items = drupal_map_assoc(array(3, 5, 10, 15, 20, 25), '_aggregator_items'); @@ -95,7 +94,8 @@ function aggregator_form_aggregator_admin_form_alter(&$form, $form_state) { $form['modules']['aggregator']['aggregator_summary_items'] = array( '#type' => 'select', '#title' => t('Number of items shown in listing pages'), - '#default_value' => config('aggregator.settings')->get('source.list_max'), + '#load' => 'config', + '#config_key' => 'source.list_max', '#empty_value' => 0, '#options' => $items, ); @@ -103,7 +103,8 @@ function aggregator_form_aggregator_admin_form_alter(&$form, $form_state) { $form['modules']['aggregator']['aggregator_clear'] = array( '#type' => 'select', '#title' => t('Discard items older than'), - '#default_value' => config('aggregator.settings')->get('items.expire'), + '#load' => 'config', + '#config_key' => 'items.expire', '#options' => $period, '#description' => t('Requires a correctly configured cron maintenance task.', array('@cron' => url('admin/reports/status'))), ); @@ -111,7 +112,8 @@ function aggregator_form_aggregator_admin_form_alter(&$form, $form_state) { $form['modules']['aggregator']['aggregator_category_selector'] = array( '#type' => 'radios', '#title' => t('Select categories using'), - '#default_value' => config('aggregator.settings')->get('source.category_selector'), + '#load' => 'config', + '#config_key' => 'source.category_selector', '#options' => array('checkboxes' => t('checkboxes'), 'select' => t('multiple selector')), '#description' => t('For a small number of categories, checkboxes are easier to use, while a multiple selector works well with large numbers of categories.'), @@ -119,7 +121,8 @@ function aggregator_form_aggregator_admin_form_alter(&$form, $form_state) { $form['modules']['aggregator']['aggregator_teaser_length'] = array( '#type' => 'select', '#title' => t('Length of trimmed description'), - '#default_value' => config('aggregator.settings')->get('items.teaser_length'), + '#load' => 'config', + '#config_key' => 'items.teaser_length', '#options' => drupal_map_assoc(array(0, 200, 400, 600, 800, 1000, 1200, 1400, 1600, 1800, 2000), '_aggregator_characters'), '#description' => t("The maximum number of characters used in the trimmed version of content.") ); diff --git a/core/modules/aggregator/lib/Drupal/aggregator/Tests/AggregatorConfigurationTest.php b/core/modules/aggregator/lib/Drupal/aggregator/Tests/AggregatorConfigurationTest.php index 65eb6ab..9273c3a 100644 --- a/core/modules/aggregator/lib/Drupal/aggregator/Tests/AggregatorConfigurationTest.php +++ b/core/modules/aggregator/lib/Drupal/aggregator/Tests/AggregatorConfigurationTest.php @@ -34,7 +34,7 @@ class AggregatorConfigurationTest extends AggregatorTestBase { $this->assertText(t('The configuration options have been saved.')); foreach ($edit as $name => $value) { - $this->assertFieldByName($name, $value, t('"@name" has correct default value.', array('@name' => $name))); + $this->assertFieldByName($name, $value); } } } diff --git a/core/modules/book/book.admin.inc b/core/modules/book/book.admin.inc index 5c414e0..dd6a086 100644 --- a/core/modules/book/book.admin.inc +++ b/core/modules/book/book.admin.inc @@ -35,11 +35,12 @@ function book_admin_overview() { */ function book_admin_settings($form, &$form_state) { $types = node_type_get_names(); - $config = config('book.settings'); + $form['#config'] = config('book.settings'); $form['book_allowed_types'] = array( '#type' => 'checkboxes', '#title' => t('Content types allowed in book outlines'), - '#default_value' => $config->get('allowed_types'), + '#load' => 'config', + '#config_key' => 'allowed_types', '#options' => $types, '#description' => t('Users with the %outline-perm permission can add all content types.', array('%outline-perm' => t('Administer book outlines'))), '#required' => TRUE, @@ -47,7 +48,8 @@ function book_admin_settings($form, &$form_state) { $form['book_child_type'] = array( '#type' => 'radios', '#title' => t('Content type for child pages'), - '#default_value' => $config->get('child_type'), + '#load' => 'config', + '#config_key' => 'child_type', '#options' => $types, '#required' => TRUE, ); @@ -68,18 +70,6 @@ function book_admin_settings_validate($form, &$form_state) { } /** - * Form submission handler for book_admin_settings(). - * - * @see book_admin_settings_validate() - */ -function book_admin_settings_submit($form, &$form_state) { - config('book.settings') - ->set('allowed_types', $form_state['values']['book_allowed_types']) - ->set('child_type', $form_state['values']['book_child_type']) - ->save(); - } - -/** * Form constructor for administering a single book's hierarchy. * * @param Drupal\node\Node $node diff --git a/core/modules/contact/contact.module b/core/modules/contact/contact.module index 1ba70b9..9abc0bd 100644 --- a/core/modules/contact/contact.module +++ b/core/modules/contact/contact.module @@ -254,19 +254,8 @@ function contact_form_user_admin_settings_alter(&$form, &$form_state) { '#type' => 'checkbox', '#title' => t('Enable the personal contact form by default for new users.'), '#description' => t('Changing this setting will not affect existing users.'), - '#default_value' => config('contact.settings')->get('user_default_enabled'), + '#load' => 'config', + '#config' => config('contact.settings'), + '#config_key' => 'user_default_enabled', ); - // Add submit handler to save contact configuration. - $form['#submit'][] = 'contact_form_user_admin_settings_submit'; -} - -/** - * Form submission handler for user_admin_settings(). - * - * @see contact_form_user_admin_settings_alter() - */ -function contact_form_user_admin_settings_submit($form, &$form_state) { - config('contact.settings') - ->set('user_default_enabled', $form_state['values']['contact_default_status']) - ->save(); } diff --git a/core/modules/dblog/dblog.module b/core/modules/dblog/dblog.module index 2e8422f..2b29660 100644 --- a/core/modules/dblog/dblog.module +++ b/core/modules/dblog/dblog.module @@ -169,21 +169,12 @@ function dblog_form_system_logging_settings_alter(&$form, $form_state) { $form['dblog_row_limit'] = array( '#type' => 'select', '#title' => t('Database log messages to keep'), - '#default_value' => config('dblog.settings')->get('row_limit'), + '#load' => 'config', + '#config' => config('dblog.settings'), + '#config_key' => 'row_limit', '#options' => array(0 => t('All')) + drupal_map_assoc(array(100, 1000, 10000, 100000, 1000000)), '#description' => t('The maximum number of messages to keep in the database log. Requires a cron maintenance task.', array('@cron' => url('admin/reports/status'))) ); - - $form['#submit'][] = 'dblog_logging_settings_submit'; -} - -/** - * Form submission handler for system_logging_settings(). - * - * @see dblog_form_system_logging_settings_alter() - */ -function dblog_logging_settings_submit($form, &$form_state) { - config('dblog.settings')->set('row_limit', $form_state['values']['dblog_row_limit'])->save(); } /** diff --git a/core/modules/forum/forum.admin.inc b/core/modules/forum/forum.admin.inc index e3c564a..aa4e400 100644 --- a/core/modules/forum/forum.admin.inc +++ b/core/modules/forum/forum.admin.inc @@ -237,43 +237,34 @@ function forum_confirm_delete_submit($form, &$form_state) { * @ingroup forms */ function forum_admin_settings($form, &$form_state) { - $config = config('forum.settings'); + $form['#config'] = config('forum.settings'); $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' => $config->get('topics.hot_threshold'), + '#load' => 'config', + '#config_key' => 'topics.hot_threshold', '#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' => $config->get('topics.page_limit'), + '#load' => 'config', + '#config_key' => 'topics.page_limit', '#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' => $config->get('topics.order'), + '#load' => 'config', + '#config_key' => 'topics.order', '#options' => $forder, '#description' => t('Default display order for topics.'), ); return system_config_form($form, $form_state); } - -/** - * Form submission handler for forum_admin_settings(). - */ -function forum_admin_settings_submit($form, &$form_state) { - config('forum.settings') - ->set('topics.hot_threshold', $form_state['values']['forum_hot_topic']) - ->set('topics.page_limit', $form_state['values']['forum_per_page']) - ->set('topics.order', $form_state['values']['forum_order']) - ->save(); -} - /** * Form constructor for the forum overview form. * diff --git a/core/modules/menu/menu.admin.inc b/core/modules/menu/menu.admin.inc index fc38caa..6b69760 100644 --- a/core/modules/menu/menu.admin.inc +++ b/core/modules/menu/menu.admin.inc @@ -690,19 +690,20 @@ function menu_reset_item_confirm_submit($form, &$form_state) { * @see menu_configure_submit() */ function menu_configure($form, &$form_state) { - $config = config('menu.settings'); + $form['#config'] = config('menu.settings'); $form['intro'] = array( '#type' => 'item', '#markup' => t('The menu module allows on-the-fly creation of menu links in the content authoring forms. To configure these settings for a particular content type, visit the Content types page, click the edit link for the content type, and go to the Menu settings section.', array('@content-types' => url('admin/structure/types'))), ); $menu_options = menu_get_menus(); + $main = $form['#config']->get('main_links'); - $main = $config->get('main_links'); $form['menu_main_links_source'] = array( '#type' => 'select', '#title' => t('Source for the Main links'), - '#default_value' => $main, + '#load' => 'config', + '#config_key' => 'main_links', '#empty_option' => t('No Main links'), '#options' => $menu_options, '#tree' => FALSE, @@ -712,7 +713,8 @@ function menu_configure($form, &$form_state) { $form['menu_secondary_links_source'] = array( '#type' => 'select', '#title' => t('Source for the Secondary links'), - '#default_value' => $config->get('secondary_links'), + '#load' => 'config', + '#config_key' => 'secondary_links', '#empty_option' => t('No Secondary links'), '#options' => $menu_options, '#tree' => FALSE, @@ -721,13 +723,3 @@ function menu_configure($form, &$form_state) { return system_config_form($form, $form_state); } - -/** - * Form submission handler for menu_configure(). - */ -function menu_configure_submit($form, &$form_state) { - config('menu.settings') - ->set('main_links', $form_state['values']['menu_main_links_source']) - ->set('secondary_links', $form_state['values']['menu_secondary_links_source']) - ->save(); -} diff --git a/core/modules/statistics/statistics.admin.inc b/core/modules/statistics/statistics.admin.inc index 176e2af..c84eb91 100644 --- a/core/modules/statistics/statistics.admin.inc +++ b/core/modules/statistics/statistics.admin.inc @@ -285,7 +285,7 @@ function statistics_access_log($aid) { * @see statistics_settings_form_submit(). */ function statistics_settings_form($form, &$form_state) { - $config = config('statistics.settings'); + $form['#config'] = config('statistics.settings'); // Access log settings. $form['access'] = array( '#type' => 'fieldset', @@ -294,13 +294,15 @@ function statistics_settings_form($form, &$form_state) { $form['access']['statistics_enable_access_log'] = array( '#type' => 'checkbox', '#title' => t('Enable access log'), - '#default_value' => $config->get('access_log.enabled'), + '#load' => 'config', + '#config_key' => 'access_log.enabled', '#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' => $config->get('access_log.max_lifetime'), + '#load' => 'config', + '#config_key' => 'access_log.max_lifetime', '#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 cron maintenance task.)', array('@cron' => url('admin/reports/status'))), ); @@ -313,20 +315,10 @@ function statistics_settings_form($form, &$form_state) { $form['content']['statistics_count_content_views'] = array( '#type' => 'checkbox', '#title' => t('Count content views'), - '#default_value' => $config->get('count_content_views'), + '#load' => 'config', + '#config_key' => 'count_content_views', '#description' => t('Increment a counter each time content is viewed.'), ); return system_config_form($form, $form_state); } - -/** - * Form submission handler for statistics_settings_form(). - */ -function statistics_settings_form_submit($form, &$form_state) { - config('statistics.settings') - ->set('access_log.enabled', $form_state['values']['statistics_enable_access_log']) - ->set('access_log.max_lifetime', $form_state['values']['statistics_flush_accesslog_timer']) - ->set('count_content_views', $form_state['values']['statistics_count_content_views']) - ->save(); -} diff --git a/core/modules/syslog/syslog.module b/core/modules/syslog/syslog.module index e138656..d708c1c 100644 --- a/core/modules/syslog/syslog.module +++ b/core/modules/syslog/syslog.module @@ -50,14 +50,18 @@ function syslog_form_system_logging_settings_alter(&$form, &$form_state) { $form['syslog_identity'] = array( '#type' => 'textfield', '#title' => t('Syslog identity'), - '#default_value' => $config->get('identity'), + '#load' => 'config', + '#config' => $config, + '#config_key' => 'identity', '#description' => t('A string that will be prepended to every message logged to Syslog. If you have multiple sites logging to the same Syslog log file, a unique identity per site makes it easy to tell the log entries apart.') . $help, ); if (defined('LOG_LOCAL0')) { $form['syslog_facility'] = array( '#type' => 'select', '#title' => t('Syslog facility'), - '#default_value' => $config->get('facility'), + '#load' => 'config', + '#config' => $config, + '#config_key' => 'facility', '#options' => syslog_facility_list(), '#description' => t('Depending on the system configuration, Syslog and other logging tools use this code to identify or filter messages from within the entire system log.') . $help, ); @@ -65,27 +69,14 @@ function syslog_form_system_logging_settings_alter(&$form, &$form_state) { $form['syslog_format'] = array( '#type' => 'textarea', '#title' => t('Syslog format'), - '#default_value' => $config->get('format'), + '#load' => 'config', + '#config' => $config, + '#config_key' => 'format', '#description' => t('Specify the format of the syslog entry. Available variables are:
!base_url
!timestamp
!type
!ip
!request_uri
!referer
!uid
!link
!message
' . t('Cron takes care of running periodic tasks like checking for updates and indexing content for search.') . '
', ); @@ -1620,7 +1613,8 @@ function system_cron_settings($form, &$form_state) { $form['cron']['cron_safe_threshold'] = array( '#type' => 'select', '#title' => t('Run cron every'), - '#default_value' => config('system.cron')->get('threshold.autorun'), + '#load' => 'config', + '#config_key' => 'threshold.autorun', '#options' => array(0 => t('Never')) + drupal_map_assoc(array(3600, 10800, 21600, 43200, 86400, 604800), 'format_interval'), ); @@ -1628,17 +1622,6 @@ function system_cron_settings($form, &$form_state) { } /** - * Form builder submit handler; Handle submission for cron settings. - * - * @ingroup forms - */ -function system_cron_settings_submit($form, &$form_state) { - config('system.cron') - ->set('threshold.autorun', $form_state['values']['cron_safe_threshold']) - ->save(); -} - -/** * Submit callback; run cron. * * @ingroup forms @@ -1662,10 +1645,13 @@ function system_run_cron_submit($form, &$form_state) { * @see system_logging_settings_submit() */ function system_logging_settings($form, &$form_state) { + $form['#config'] = config('system.logging'); + $form['error_level'] = array( '#type' => 'radios', '#title' => t('Error messages to display'), - '#default_value' => config('system.logging')->get('error_level'), + '#load' => 'config', + '#config_key' => 'error_level', '#options' => array( ERROR_REPORTING_HIDE => t('None'), ERROR_REPORTING_DISPLAY_SOME => t('Errors and warnings'), @@ -1679,17 +1665,6 @@ function system_logging_settings($form, &$form_state) { } /** - * Form submission handler for system_logging_settings(). - * - * @ingroup forms - */ -function system_logging_settings_submit($form, &$form_state) { - config('system.logging') - ->set('error_level', $form_state['values']['error_level']) - ->save(); -} - -/** * Form builder; Configure site performance settings. * * @ingroup forms @@ -1697,7 +1672,7 @@ function system_logging_settings_submit($form, &$form_state) { */ function system_performance_settings($form, &$form_state) { drupal_add_library('system', 'drupal.system'); - $config = config('system.performance'); + $form['#config'] = config('system.performance'); $form['clear_cache'] = array( '#type' => 'fieldset', @@ -1718,7 +1693,8 @@ function system_performance_settings($form, &$form_state) { $form['caching']['cache'] = array( '#type' => 'checkbox', '#title' => t('Cache pages for anonymous users'), - '#default_value' => $config->get('cache.page.enabled'), + '#load' => 'config', + '#config_key' => 'cache.page.enabled', '#weight' => -2, ); @@ -1727,7 +1703,8 @@ function system_performance_settings($form, &$form_state) { $form['caching']['page_cache_maximum_age'] = array( '#type' => 'select', '#title' => t('Expiration of cached pages'), - '#default_value' => $config->get('cache.page.max_age'), + '#load' => 'config', + '#config_key' => 'cache.page.max_age', '#options' => $period, '#description' => t('The maximum time an external cache can use an old version of a page.'), ); @@ -1746,24 +1723,27 @@ function system_performance_settings($form, &$form_state) { '#description' => t('External resources can be optimized automatically, which can reduce both the size and number of requests made to your website.') . $disabled_message, ); - $js_hide = $config->get('cache.page.enabled') ? '' : ' class="js-hide"'; + $js_hide = $form['#config']->get('cache.page.enabled') ? '' : ' class="js-hide"'; $form['bandwidth_optimization']['page_compression'] = array( '#type' => 'checkbox', '#title' => t('Compress cached pages.'), - '#default_value' => $config->get('response.gzip'), + '#load' => 'config', + '#config_key' => 'response.gzip', '#prefix' => '