Problem/Motivation

The GUI does not retain the checked setting for "Force single use tokens". The database definitely has the correct configuration as proven by doing a drush cex and seeing that the resultant yml files do change as the settings is changed in the GUI. However, the checkbox in the GUI never shows checked (even when the setting really is true)

Steps to reproduce

  1. Install latest Drupal 9 using composer create-project drupal/recommended-project
  2. Configure Drupal using the GUI
  3. composer require drupal/anonymous_token
  4. Login as admin
  5. Enable Anonymous CSRF Token module using the GUI
  6. Clear all caches
  7. Go to the settings page /admin/config/system/anonymous-csrf-token
  8. Check "Force single use tokens"
  9. Click Save configuration
  10. The checkbox does not remain checked
  11. Clear cache and navigate back to the page. It still isn't checked.

Proposed resolution

The error only happens with a new install because there is no setting as of yet. The null coallesce isn't working as you would think on a fresh install. Fix line 39 in src/Form/SettingsForm.php
'#defalt_value' => $config->get('force_single_use') ?? FALSE,

Remaining tasks

User interface changes

API changes

Data model changes

Comments

Timothy.Siford created an issue. See original summary.

baikho’s picture

Version: 2.0.0-beta2 » 2.x-dev
Issue tags: +Novice

Thanks for the bug report!

  • baikho committed ab29032 on 2.x
    Issue #3183046 by Timothy.Siford, baikho: GUI Setting "Force single use...
baikho’s picture

Status: Active » Fixed

Fixed now, will tag a new release.

diff --git a/src/Form/SettingsForm.php b/src/Form/SettingsForm.php
index c2c927c..bdae399 100644
--- a/src/Form/SettingsForm.php
+++ b/src/Form/SettingsForm.php
@@ -36,7 +36,7 @@ class SettingsForm extends ConfigFormBase {
     $form['force_single_use'] = [
       '#title' => $this->t('Force single use tokens'),
       '#type' => 'checkbox',
-      '#defalt_value' => $config->get('force_single_use') ?? FALSE,
+      '#default_value' => $config->get('force_single_use') ?? FALSE,
     ];

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.