Problem/Motivation

When building the Image CAPTCHA settings form (ImageCaptchaSettingsForm::settingsDotSection()), the module scans font directories and writes the font preview map directly into active configuration (image_captcha.settings) on every GET request:

$fonts = _image_captcha_get_available_fonts_from_directories();
$config->set('image_captcha_fonts_preview_map_cache', $fonts);
$config->save();

This causes multiple issues:

  • A GET request should never modify persistent site configuration.
  • It causes spurious configuration diffs in drush config:status and breaks configuration synchronization workflows.
  • It breaks read-only environments and modules like Drupal Workspaces that prevent config writes during form display.

Proposed resolution

  • Use Drupal's Cache API (\Drupal::cache()) inside _image_captcha_get_available_fonts_from_directories() instead of saving to configuration.
  • Remove $config->set('image_captcha_fonts_preview_map_cache', ...) and $config->save() from ImageCaptchaSettingsForm.
  • Update CaptchaFontPreviewController and image_captcha_font_preview() to retrieve fonts from _image_captcha_get_available_fonts_from_directories().
  • Remove image_captcha_fonts_preview_map_cache from image_captcha.settings.yml install and schema definitions.
  • Provide a post-update function image_captcha_post_update_remove_fonts_preview_map_cache() to remove the key from active configurations on existing sites.
  • Add test assertions to verify image_captcha.settings is not modified upon visiting the settings form.

Remaining tasks

  • Maintainer review

User interface changes

None

Introduced terminology

None

API changes

None

Data model changes

Removed image_captcha_fonts_preview_map_cache from image_captcha.settings schema and active config.

Release notes snippet

Fixed an issue where visiting the Image CAPTCHA settings form modified active configuration.

Issue fork captcha-3641565

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

ajits created an issue. See original summary.

keerthi kumar’s picture

Assigned: Unassigned » keerthi kumar

I would like to work on this!

keerthi kumar’s picture

Issue summary: View changes
keerthi kumar’s picture

Status: Active » Needs review

Created Merge Request. Replaced config-based caching with Drupal's Cache API in _image_captcha_get_available_fonts_from_directories(), removed config writes from the settings form build step, added a post-update hook to clean up active config, and added functional test assertions.