Follow-up to:
- #1324618: Implement automated config saving for simple settings forms
- #1696224: Remove system_settings_form()
- #1653026: [META] Use properly typed values in module configuration

Problem

  • Module settings forms were converted to the configuration system, but $form structures haven't been changed, since it was unclear whether there would be an automation.

Goal

  • Update all module settings forms to use appropriate $form array keys for configuration setting keys.

Proposed guideline

Given:

  • A module settings form; e.g., PerformanceForm
  • A system.performance.yml config object containing (among other keys):
    cache:
        page:
            enabled: '0'
    
  • And a $form definition of:
        $form['caching']['cache'] = array(
          '#type' => 'checkbox',
          '#title' => t('Use internal page cache'),
          '#description' => t("If a reverse proxy cache isn't available, use Drupal's internal cache system to store cached pages."),
          '#default_value' => $config->get('cache.page.use_internal'),
        );
    

Then:

  1. Update the $form array key to equal the config object key in dot-notion:
    -   $form['caching']['cache'] = array(
    +   $form['caching']['cache.page.enabled'] = array(
          '#type' => 'checkbox',
          '#title' => t('Use internal page cache'),
          '#default_value' => $config->get('cache.page.enabled'),
          '#weight' => -2,
        );
    
  2. Update the form submission handler to look for the changed key in the submitted form values:
      public function submitForm(array &$form, array &$form_state) {
        [...]
        $this->config('system.performance')
    -      ->set('cache.page.use_internal', $form_state['values']['cache'])
    +      ->set('cache.page.use_internal', $form_state['values']['cache.page.enabled'])
           ->set('cache.page.max_age', $form_state['values']['page_cache_maximum_age'])
    
  3. Determine which data type(s) is expected for the configuration object value:
            enabled: '0'
    

    Original report by @sun

Comments

mtift’s picture

Issue summary: View changes
Issue tags: +beta deadline

The casting part of the original report is handled, but the form array part is not, so I updated the summary.

And just to clarify the tags:
beta target == "we'd like to have this in some beta"
beta deadline == "if we don't do this by beta1 we don't do it in 8.0.x"

catch’s picture

Issue tags: -beta deadline +beta target

Admin configuration form array structures aren't a critical API, so this can still be beta target or possibly even minor version target.

xjm’s picture

Issue tags: -beta target

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.