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
Base URL of the site.
!timestamp
Unix timestamp of the log entry.
!type
The category to which this message belongs.
!ip
IP address of the user triggering the message.
!request_uri
The requested URI.
!referer
HTTP Referer if available.
!uid
User ID.
!link
A link to associate with the message.
!message
The message to store in the log.
'), ); - - $form['#submit'][] = 'syslog_logging_settings_submit'; } /** - * Form submission handler for system_logging_settings(). - * - * @see syslog_form_system_logging_settings_alter() - */ -function syslog_logging_settings_submit($form, &$form_state) { - config('syslog.settings') - ->set('identity', $form_state['values']['syslog_identity']) - ->set('facility', $form_state['values']['syslog_facility']) - ->set('format', $form_state['values']['syslog_format']) - ->save(); -} - - /** * Lists all possible syslog facilities for UNIX/Linux. * * @return array diff --git a/core/modules/system/system.admin.inc b/core/modules/system/system.admin.inc index 3ccb13b..30713fc 100644 --- a/core/modules/system/system.admin.inc +++ b/core/modules/system/system.admin.inc @@ -1479,7 +1479,7 @@ function system_ip_blocking_delete_submit($form, &$form_state) { * @see system_settings_form() */ function system_site_information_settings($form, &$form_state) { - $site_config = config('system.site'); + $form['#config'] = config('system.site'); $site_mail = $site_config->get('mail'); if (empty($site_mail)) { $site_mail = ini_get('sendmail_from'); @@ -1492,13 +1492,15 @@ function system_site_information_settings($form, &$form_state) { $form['site_information']['site_name'] = array( '#type' => 'textfield', '#title' => t('Site name'), - '#default_value' => $site_config->get('name'), + '#load' => 'config', + '#config_key' => 'name', '#required' => TRUE ); $form['site_information']['site_slogan'] = array( '#type' => 'textfield', '#title' => t('Slogan'), - '#default_value' => $site_config->get('slogan'), + '#load' => 'config', + '#config_key' => 'slogan', '#description' => t("How this is used depends on your site's theme."), ); $form['site_information']['site_mail'] = array( @@ -1515,7 +1517,8 @@ function system_site_information_settings($form, &$form_state) { $form['front_page']['site_frontpage'] = array( '#type' => 'textfield', '#title' => t('Default front page'), - '#default_value' => ($site_config->get('page.front') != 'user' ? drupal_get_path_alias($site_config->get('page.front')) : ''), + '#load' => 'config', + '#config_key' => 'page.front' != 'user' ? drupal_get_path_alias($site_config->get('page.front')) : '', '#size' => 40, '#description' => t('Optionally, specify a relative URL to display as the front page. Leave blank to display the default content feed.'), '#field_prefix' => url(NULL, array('absolute' => TRUE)), @@ -1527,7 +1530,8 @@ function system_site_information_settings($form, &$form_state) { $form['error_page']['site_403'] = array( '#type' => 'textfield', '#title' => t('Default 403 (access denied) page'), - '#default_value' => $site_config->get('page.403'), + '#load' => 'config', + '#config_key' => 'page.403', '#size' => 40, '#description' => t('This page is displayed when the requested document is denied to the current user. Leave blank to display a generic "access denied" page.'), '#field_prefix' => url(NULL, array('absolute' => TRUE)), @@ -1535,7 +1539,8 @@ function system_site_information_settings($form, &$form_state) { $form['error_page']['site_404'] = array( '#type' => 'textfield', '#title' => t('Default 404 (not found) page'), - '#default_value' => $site_config->get('page.404'), + '#load' => 'config', + '#config_key' => 'page.404', '#size' => 40, '#description' => t('This page is displayed when no other content matches the requested document. Leave blank to display a generic "page not found" page.'), '#field_prefix' => url(NULL, array('absolute' => TRUE)), @@ -1581,25 +1586,13 @@ function system_site_information_settings_validate($form, &$form_state) { } /** - * Form submission handler for system_site_information_settings(). - */ -function system_site_information_settings_submit($form, &$form_state) { - config('system.site') - ->set('name', $form_state['values']['site_name']) - ->set('mail', $form_state['values']['site_mail']) - ->set('slogan', $form_state['values']['site_slogan']) - ->set('page.front', $form_state['values']['site_frontpage']) - ->set('page.403', $form_state['values']['site_403']) - ->set('page.404', $form_state['values']['site_404']) - ->save(); -} - -/** * Form builder; Cron form. * * @ingroup forms */ function system_cron_settings($form, &$form_state) { + $form['#config'] = config('system.cron'); + $form['description'] = array( '#markup' => '

' . 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' => '
', '#suffix' => '
', ); $form['bandwidth_optimization']['preprocess_css'] = array( '#type' => 'checkbox', '#title' => t('Aggregate and compress CSS files.'), - '#default_value' => $config->get('preprocess.css'), + '#load' => 'config', + '#config_key' => 'preprocess.css', '#disabled' => $disabled, ); $form['bandwidth_optimization']['preprocess_js'] = array( '#type' => 'checkbox', '#title' => t('Aggregate JavaScript files.'), - '#default_value' => $config->get('preprocess.js'), + '#load' => 'config', + '#config_key' => 'preprocess.js', '#disabled' => $disabled, ); @@ -1772,27 +1752,11 @@ function system_performance_settings($form, &$form_state) { // This form allows page compression settings to be changed, which can // invalidate the page cache, so it needs to be cleared on form submit. $form['#submit'][] = 'system_clear_page_cache_submit'; - $form['#submit'][] = 'system_performance_settings_submit'; return system_config_form($form, $form_state); } /** - * Form submission handler for system_performance_settings(). - * - * @ingroup forms - */ -function system_performance_settings_submit($form, &$form_state) { - $config = config('system.performance'); - $config->set('cache.page.enabled', $form_state['values']['cache']); - $config->set('cache.page.max_age', $form_state['values']['page_cache_maximum_age']); - $config->set('response.gzip', $form_state['values']['page_compression']); - $config->set('preprocess.css', $form_state['values']['preprocess_css']); - $config->set('preprocess.js', $form_state['values']['preprocess_js']); - $config->save(); -} - -/** * Submit callback; clear system caches. * * @ingroup forms @@ -1908,24 +1872,28 @@ function system_image_toolkit_settings() { * @ingroup forms */ function system_rss_feeds_settings($form, &$form_state) { - $rss_config = config('system.rss'); + $form['#config'] = config('system.rss'); + $form['feed_description'] = array( '#type' => 'textarea', '#title' => t('Feed description'), - '#default_value' => $rss_config->get('channel.description'), + '#load' => 'config', + '#config_key' => 'channel.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' => $rss_config->get('items.limit'), + '#load' => 'config', + '#config_key' => 'items.limit', '#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' => $rss_config->get('items.view_mode'), + '#load' => 'config', + '#config_key' => 'items.view_mode', '#options' => array( 'title' => t('Titles only'), 'teaser' => t('Titles plus teaser'), @@ -1938,19 +1906,6 @@ function system_rss_feeds_settings($form, &$form_state) { } /** - * Form builder submit handler; Handle submission for RSS feeds settings. - * - * @ingroup forms - */ -function system_rss_feeds_settings_submit($form, &$form_state) { - config('system.rss') - ->set('channel.description', $form_state['values']['feed_description']) - ->set('items.limit', $form_state['values']['feed_default_items']) - ->set('items.view_mode', $form_state['values']['feed_item_length']) - ->save(); -} - -/** * Form builder; Configure the site regional settings. * * @ingroup forms @@ -2249,35 +2204,25 @@ function system_date_time_lookup() { * @see system_site_maintenance_mode_submit() */ function system_site_maintenance_mode($form, &$form_state) { - $config = config('system.maintenance'); + $form['#config'] = config('system.maintenance'); $form['maintenance_mode'] = array( '#type' => 'checkbox', '#title' => t('Put site into maintenance mode'), - '#default_value' => $config->get('enabled'), + '#load' => 'config', + '#config_key' => 'enabled', '#description' => t('Visitors will only see the maintenance mode message. Only users with the "Access site in maintenance mode" permission will be able to access the site. Authorized users can log in directly via the user login page.', array('@permissions-url' => url('admin/config/people/permissions'), '@user-login' => url('user'))), ); $form['maintenance_mode_message'] = array( '#type' => 'textarea', '#title' => t('Message to display when in maintenance mode'), - '#default_value' => $config->get('message'), + '#load' => 'config', + '#config_key' => 'message', ); return system_config_form($form, $form_state); } /** - * Form submission handler for system_site_maintenance_mode(). - * - * @ingroup forms - */ -function system_site_maintenance_mode_submit($form, &$form_state) { - config('system.maintenance') - ->set('enabled', $form_state['values']['maintenance_mode']) - ->set('message', $form_state['values']['maintenance_mode_message']) - ->save(); -} - -/** * Menu callback: displays the site status report. Can also be used as a pure check. * * @param $check diff --git a/core/modules/system/system.module b/core/modules/system/system.module index c151ef0..a11329a 100644 --- a/core/modules/system/system.module +++ b/core/modules/system/system.module @@ -6,6 +6,7 @@ */ use Drupal\Core\Utility\ModuleInfo; +use Drupal\Component\Utility\NestedArray; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Response; @@ -3234,6 +3235,14 @@ function system_settings_form_submit($form, &$form_state) { * http://drupal.org/node/1324618. */ function system_config_form($form, &$form_state) { + $config = isset($form['#config']) ? $form['#config'] : NULL; + $form_state['callbacks']['load']['config'] = function ($element) use ($config) { + if (isset($element['#config'])) { + $config = $element['#config']; + } + return $config->get($element['#config_key']); + }; + $form['actions']['#type'] = 'actions'; $form['actions']['submit'] = array( '#type' => 'submit', @@ -3267,6 +3276,13 @@ function system_config_form($form, &$form_state) { * @see system_config_form() */ function system_config_form_submit($form, &$form_state) { + foreach ($form_state['loadables']['config'] as $array_parents) { + $element = NestedArray::getValue($form, $array_parents); + $value = ($element['#type'] == 'checkboxes') ? array_keys(array_filter($element['#value'])) : $element['#value']; + $config = isset($element['#config']) ? $element['#config'] : $form['#config']; + $config->set($element['#config_key'], $value); + } + $config->save(); drupal_set_message(t('The configuration options have been saved.')); } diff --git a/core/modules/update/update.settings.inc b/core/modules/update/update.settings.inc index 0a5e337..ca9d47d 100644 --- a/core/modules/update/update.settings.inc +++ b/core/modules/update/update.settings.inc @@ -13,11 +13,12 @@ * @ingroup forms */ function update_settings($form, &$form_state) { - $config = config('update.settings'); + $form['#config'] = config('update.settings'); $form['update_check_frequency'] = array( '#type' => 'radios', '#title' => t('Check for updates'), - '#default_value' => $config->get('check.interval_days'), + '#load' => 'config', + '#config_key' => 'check.interval_days', '#options' => array( '1' => t('Daily'), '7' => t('Weekly'), @@ -28,22 +29,23 @@ function update_settings($form, &$form_state) { $form['update_check_disabled'] = array( '#type' => 'checkbox', '#title' => t('Check for updates of disabled modules and themes'), - '#default_value' => $config->get('check.disabled_extensions'), + '#load' => 'config', + '#config_key' => 'check.disabled_extensions', ); - $notification_emails = $config->get('notification.emails'); $form['update_notify_emails'] = array( '#type' => 'textarea', '#title' => t('E-mail addresses to notify when updates are available'), '#rows' => 4, - '#default_value' => implode("\n", $notification_emails), + '#default_value' => implode("\n", $form['#config']->get('notification.emails')), '#description' => t('Whenever your site checks for available updates and finds new releases, it can notify a list of users via e-mail. Put each address on a separate line. If blank, no e-mails will be sent.'), ); $form['update_notification_threshold'] = array( '#type' => 'radios', '#title' => t('E-mail notification threshold'), - '#default_value' => $config->get('notification.threshold'), + '#load' => 'config', + '#config_key' => 'notification.threshold', '#options' => array( 'all' => t('All newer versions'), 'security' => t('Only security updates'), @@ -110,9 +112,6 @@ function update_settings_submit($form, $form_state) { } $config - ->set('check.disabled_extensions', $form_state['values']['update_check_disabled']) - ->set('check.interval_days', $form_state['values']['update_check_frequency']) ->set('notification.emails', $form_state['notify_emails']) - ->set('notification.threshold', $form_state['values']['update_notification_threshold']) ->save(); }