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..25fa8ce 100644 --- a/core/modules/aggregator/aggregator.admin.inc +++ b/core/modules/aggregator/aggregator.admin.inc @@ -428,14 +428,15 @@ 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) { // 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 +485,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 +495,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 +505,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)) { @@ -518,35 +522,12 @@ function aggregator_admin_form($form, $form_state) { // Implementing modules will expect an array at $form['modules']. $form['modules'] = array(); + $form['#config'] = config('aggregator.settings'); return system_config_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..4303618 100644 --- a/core/modules/aggregator/aggregator.processor.inc +++ b/core/modules/aggregator/aggregator.processor.inc @@ -95,7 +95,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 +104,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 +113,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 +122,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/book/book.module b/core/modules/book/book.module index 7e7ca52..26713bd 100644 --- a/core/modules/book/book.module +++ b/core/modules/book/book.module @@ -342,22 +342,15 @@ function book_block_configure($delta = '') { '#type' => 'radios', '#title' => t('Book navigation block display'), '#options' => $options, - '#default_value' => config('book.settings')->get('block.navigation.mode'), + '#load' => 'config', + '#config' => config('book.settings'), + '#config_key' => 'block.navigation.mode', '#description' => t("If Show block on all pages is selected, the block will contain the automatically generated menus for all of the site's books. If Show block only on book pages is selected, the block will contain only the one menu corresponding to the current page's book. In this case, if the current page is not in a book, no block will be displayed. The Page specific visibility settings or other visibility settings can be used in addition to selectively display this block."), - ); - + ); return $form; } /** - * Implements hook_block_save(). - */ -function book_block_save($delta = '', $edit = array()) { - $block = array(); - config('book.settings')->set('block.navigation.mode', $edit['book_block_mode'])->save(); -} - -/** * Returns HTML for a link to a book title when used as a block title. * * @param $variables diff --git a/core/modules/contact/contact.module b/core/modules/contact/contact.module index 1ba70b9..c749cb6 100644 --- a/core/modules/contact/contact.module +++ b/core/modules/contact/contact.module @@ -254,7 +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_key' => 'user_default_enabled', ); // Add submit handler to save contact configuration. $form['#submit'][] = 'contact_form_user_admin_settings_submit'; diff --git a/core/modules/dblog/dblog.module b/core/modules/dblog/dblog.module index 2e8422f..2d98c95 100644 --- a/core/modules/dblog/dblog.module +++ b/core/modules/dblog/dblog.module @@ -169,7 +169,8 @@ 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_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'))) ); diff --git a/core/modules/forum/forum.admin.inc b/core/modules/forum/forum.admin.inc index e3c564a..739b1aa 100644 --- a/core/modules/forum/forum.admin.inc +++ b/core/modules/forum/forum.admin.inc @@ -241,21 +241,24 @@ function forum_admin_settings($form, &$form_state) { $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.'), ); diff --git a/core/modules/forum/forum.module b/core/modules/forum/forum.module index 30b1e6b..fff6123 100644 --- a/core/modules/forum/forum.module +++ b/core/modules/forum/forum.module @@ -663,7 +663,8 @@ function forum_block_configure($delta = '') { $form['block_num_' . $delta] = array( '#type' => 'select', '#title' => t('Number of topics'), - '#default_value' => config('forum.settings')->get('block.num_' . $delta), + '#load' => 'config', + '#config_key' => 'block.num_' . $delta, '#options' => drupal_map_assoc(range(2, 20)), ); return $form; diff --git a/core/modules/menu/menu.admin.inc b/core/modules/menu/menu.admin.inc index fc38caa..81f3fda 100644 --- a/core/modules/menu/menu.admin.inc +++ b/core/modules/menu/menu.admin.inc @@ -712,7 +712,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, diff --git a/core/modules/search/search.admin.inc b/core/modules/search/search.admin.inc index 9168510..034902b 100644 --- a/core/modules/search/search.admin.inc +++ b/core/modules/search/search.admin.inc @@ -75,7 +75,8 @@ function search_admin_settings($form, &$form_state) { $form['indexing_throttle']['cron_limit'] = array( '#type' => 'select', '#title' => t('Number of items to index per cron run'), - '#default_value' => $config->get('index.cron_limit'), + '#load' => 'config', + '#config_key' => 'index.cron_limit', '#options' => $items, '#description' => t('The maximum number of items indexed in each pass of a cron maintenance task. If necessary, reduce the number of items to prevent timeouts and memory errors while indexing.', array('@cron' => url('admin/reports/status'))) ); @@ -90,7 +91,8 @@ function search_admin_settings($form, &$form_state) { $form['indexing_settings']['minimum_word_size'] = array( '#type' => 'number', '#title' => t('Minimum word length to index'), - '#default_value' => $config->get('index.minimum_word_size'), + '#load' => 'config', + '#config_key' => 'index.minimum_word_size', '#min' => 1, '#max' => 1000, '#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).') @@ -98,7 +100,8 @@ function search_admin_settings($form, &$form_state) { $form['indexing_settings']['overlap_cjk'] = array( '#type' => 'checkbox', '#title' => t('Simple CJK handling'), - '#default_value' => $config->get('index.overlap_cjk'), + '#load' => 'config', + '#config_key' => 'index.overlap_cjk', '#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.') ); @@ -111,14 +114,16 @@ function search_admin_settings($form, &$form_state) { '#type' => 'checkboxes', '#title' => t('Active modules'), '#title_display' => 'invisible', - '#default_value' => $config->get('active_modules'), + '#load' => 'config', + '#config_key' => 'active_modules', '#options' => $module_options, '#description' => t('Choose which search modules are active from the available modules.') ); $form['active']['default_module'] = array( '#title' => t('Default search module'), '#type' => 'radios', - '#default_value' => $config->get('default_module'), + '#load' => 'config', + '#config_key' => 'default_module', '#options' => $module_options, '#description' => t('Choose which search module is the default.') ); diff --git a/core/modules/statistics/statistics.admin.inc b/core/modules/statistics/statistics.admin.inc index 176e2af..2d02cbc 100644 --- a/core/modules/statistics/statistics.admin.inc +++ b/core/modules/statistics/statistics.admin.inc @@ -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,7 +315,8 @@ 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.'), ); diff --git a/core/modules/statistics/statistics.module b/core/modules/statistics/statistics.module index c07a1c8..1d9b580 100644 --- a/core/modules/statistics/statistics.module +++ b/core/modules/statistics/statistics.module @@ -325,9 +325,33 @@ function statistics_block_configure($delta = '') { $config = config('statistics.settings'); // Popular content block settings $numbers = array('0' => t('Disabled')) + drupal_map_assoc(array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 25, 30, 40)); - $form['statistics_block_popular_top_day_limit'] = array('#type' => 'select', '#title' => t("Number of day's top views to display"), '#default_value' => $config->get('block.popular.top_day_limit'), '#options' => $numbers, '#description' => t('How many content items to display in "day" list.')); - $form['statistics_block_popular_top_all_limit'] = array('#type' => 'select', '#title' => t('Number of all time views to display'), '#default_value' => $config->get('block.popular.top_all_limit'), '#options' => $numbers, '#description' => t('How many content items to display in "all time" list.')); - $form['statistics_block_popular_top_recent_limit'] = array('#type' => 'select', '#title' => t('Number of most recent views to display'), '#default_value' => $config->get('block.popular.top_recent_limit'), '#options' => $numbers, '#description' => t('How many content items to display in "recently viewed" list.')); + $form['statistics_block_popular_top_day_limit'] = array( + '#type' => 'select', + '#title' => t("Number of day's top views to display"), + '#load' => 'config', + '#config' => $config, + '#config_key' => 'block.popular.top_day_limit', + '#options' => $numbers, + '#description' => t('How many content items to display in "day" list.'), + ); + $form['statistics_block_popular_top_all_limit'] = array( + '#type' => 'select', + '#title' => t('Number of all time views to display'), + '#load' => 'config', + '#config' => $config, + '#config_key' => 'block.popular.top_all_limit', + '#options' => $numbers, + '#description' => t('How many content items to display in "all time" list.'), + ); + $form['statistics_block_popular_top_recent_limit'] = array( + '#type' => 'select', + '#title' => t('Number of most recent views to display'), + '#load' => 'config', + '#config' => $config, + '#config_key' => 'block.popular.top_recent_limit', + '#options' => $numbers, + '#description' => t('How many content items to display in "recently viewed" list.'), + ); return $form; } diff --git a/core/modules/syslog/syslog.module b/core/modules/syslog/syslog.module index e138656..b137640 100644 --- a/core/modules/syslog/syslog.module +++ b/core/modules/syslog/syslog.module @@ -50,14 +50,16 @@ 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_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_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,7 +67,8 @@ 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_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.
'), ); diff --git a/core/modules/system/system.admin.inc b/core/modules/system/system.admin.inc index 3ccb13b..cc2d389 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,20 +1586,6 @@ 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 @@ -1620,25 +1611,16 @@ 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'), ); + $form['#config'] = config('system.cron'); return system_config_form($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 @@ -1665,7 +1647,8 @@ function system_logging_settings($form, &$form_state) { $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'), @@ -1674,22 +1657,12 @@ function system_logging_settings($form, &$form_state) { ), '#description' => t('It is recommended that sites running on production environments do not display any errors.'), ); + $form['#config'] = config('system.logging'); return system_config_form($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 +1670,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 +1691,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 +1701,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 +1721,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 +1750,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 @@ -1912,20 +1874,26 @@ function system_rss_feeds_settings($form, &$form_state) { $form['feed_description'] = array( '#type' => 'textarea', '#title' => t('Feed description'), - '#default_value' => $rss_config->get('channel.description'), + '#load' => 'config', + '#config' => $rss_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' => $rss_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' => $rss_config, + '#config_key' => 'items.view_mode', '#options' => array( 'title' => t('Titles only'), 'teaser' => t('Titles plus teaser'), @@ -2253,13 +2221,15 @@ function system_site_maintenance_mode($form, &$form_state) { $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); diff --git a/core/modules/system/system.module b/core/modules/system/system.module index c151ef0..e5d4f50 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; @@ -3190,6 +3191,13 @@ function system_settings_form($form) { if (!isset($form['#theme'])) { $form['#theme'] = 'system_settings_form'; } + $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']); + }; return $form; } @@ -3267,6 +3275,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..962f367 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,7 +29,8 @@ 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'); @@ -43,7 +45,8 @@ function update_settings($form, &$form_state) { $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'), @@ -108,11 +111,4 @@ function update_settings_submit($form, $form_state) { if ($form_state['values']['update_check_disabled'] != $config->get('check.disabled_extensions')) { _update_cache_clear(); } - - $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(); }