Unnecessary items in config file

Created on 19 September 2024, about 2 months ago

First of all, thanks for the nice module!
It seems to do what it's supposed to do, but I noticed a small bug/unexpected feature when installing the module and saving the settings form (and exporting configs).

Problem/Motivation

After installation and after saving module settings form unnecessary items will be added to the module configuration file "user_prune.settings.yml"

Those items are described here:

  • After installation:

message: Hello
(This seems to come from user_prune/config/install/user_prune.settings.yml)

  • After saving the settings form (the values for these are left out on purpose):
submit: 
form_build_id: 
form_token: 
form_id:
op:

This happens most likely because how the settings are saved in "user_prune/src/Form/UserPruneSettingsForm.php"

public function submitForm(array &$form, FormStateInterface $form_state) {
    $config = $this->config('user_prune.settings');
    foreach ($form_state->getValues() as $key => $value) {
      $config->set($key, $value);
    }
    $config->save();
    $this->messenger()->addStatus($this->t("Configuration saved!"));
  }

I believe $form_state->getValues() contains more than just the intended form input fields and thus unnecessary form element values gets added to the module configuration file.

Steps to reproduce

  1. Install user_prune version 1.5
  2. Go to the module settings page at /admin/structure/user-prune/settings
  3. Save settings
  4. Export site configs with drush cex and view the "user_prune.settings.yml" file from your config sync directory

Proposed resolution

  • Remove "message: Hello" from the install config file (probably there by a mistake?) as the module doesn't need it anywhere
  • Adjust how form values are gathered in the foreach loop: foreach ($form_state->getValues() so unnecessary input fields would not end up in the module config file

Remaining tasks

  • fix install config file
  • fix "public function submitForm"
  • maybe fix existing config files in update hook?

User interface changes

  • none

API changes

  • none

Data model changes

  • none, I guess?
🐛 Bug report
Status

Active

Version

1.5

Component

Code

Created by

🇫🇮Finland hartsak

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

Comments & Activities

Production build 0.71.5 2024