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

Issue fork captcha-3375618

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

Anybody created an issue. See original summary.

anybody’s picture

Issue summary: View changes
pbouchereau’s picture

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.

japerry made their first commit to this issue’s fork.

  • japerry committed 1b13f8e4 on 2.x
    fix: #3375618 Show the image CAPTCHA refresh link for the 'default' type
    
japerry’s picture

Status: Active » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.