[meta] Update module settings $form arrays

Created on 2 September 2012, over 12 years ago
Updated 14 February 2024, 11 months ago

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

πŸ“Œ Task
Status

Closed: outdated

Version

9.5

Component
ConfigurationΒ  β†’

Last updated about 17 hours ago

Created by

πŸ‡©πŸ‡ͺGermany sun Karlsruhe

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024