Allow using "default" #captcha_type for the captcha form element

Created on 19 July 2023, over 1 year ago
Updated 24 November 2023, about 1 year ago

Problem/Motivation

When adding a captcha to a form by using the captcha form element, you can't simply use "default" as #captcha_type, while it would be nice to be able to do so. Currently you have to retrieve the default challenge from captcha like this:

    $default_challenge = \Drupal::service('config.manager')
      ->getConfigFactory()
      ->get('captcha.settings')
      ->get('default_challenge');

    $form['captcha'] = [
      '#type' => 'captcha',
      '#captcha_type' => $default_challenge,
    ];

For example see the famous Webform module, which has to use this code.

Steps to reproduce

Proposed resolution

Allow using

$form['captcha'] = [
      '#type' => 'captcha',
      '#captcha_type' => 'default',
    ];

(or another placeholder value) and replace "default" by the default captcha type in the captcha module, before processing the element. That way other modules don't have to know about CAPTCHA modules internals.

Remaining tasks

User interface changes

API changes

Data model changes

Feature request
Status

Active

Version

2.0

Component

Code

Created by

🇩🇪Germany Anybody Porta Westfalica

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

Comments & Activities

  • Issue created by @Anybody
  • 🇩🇪Germany Anybody Porta Westfalica
  • Hi,

    The mentioned code snippet was executed in image_captcha.module file in previous versions.
    It hasn't been ported to the imageCaptchaAfterBuildProcess() function in ImageCaptchaRenderService.php.

    Because of this my setup partly broke when I updated.
    I had "Image captcha" set as default in captcha global settings and "default" set in a captcha point for my user login form.
    After updating the reload button was not displayed anymore because the image captcha type was not detected.

Production build 0.71.5 2024