Problem/Motivation

Currently, when using image_captcha/Image captcha type, it works perfectly fine inside added captcha points. But if we would like to use it inside a form, the refresh button is missing.

The reason is the following:

If we render the image captcha inside a captcha point, we first render the generel captcha data with our image_captcha data given to the captcha.html.twig. Once this is done, we use "image_captcha_element_info_alter" in our image_captcha module to post process our form and add the refresh button, to the form.

Unfortunately, this post-processing won't take place if we insert a captcha form element inside a form via '#type' => 'captcha' and therefore the refresh button is missing.

Steps to reproduce

Add:

    $form['test'] = [
      '#type' => 'captcha',
      '#captcha_type' => 'image_captcha/Image',
      '#captcha_admin_mode' => TRUE,
    ];

Inside a test form and check the output.

Proposed resolution

Implement something like "$captcha['post_process']" inside "hook_captcha_captcha" to let submodules register form postprocessing inside their custom captcha's "hook_captcha_captcha".

Remaining tasks

User interface changes

API changes

Data model changes

Issue fork captcha-3326503

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:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Grevil created an issue. See original summary.

Grevil’s picture

Issue summary: View changes
Grevil’s picture

Issue summary: View changes
Anybody’s picture

Yes, please fix this and add tests to ensure it doesn't break again.

Anybody’s picture

Assigned: Unassigned » Grevil
Status: Active » Needs work

Test fail.

Grevil’s picture

Status: Needs work » Needs review
Anybody’s picture

Status: Needs review » Needs work

The test should be working, otherwise we're doing something wrong here.

Please have a look at the test form output manually.

Anybody’s picture

Super nice cleanup BTW @Grevil! Thx :)

It's worth to fix this clean finally. Good job.

Grevil’s picture

Status: Needs work » Needs review

All fixed, please review once again!

Anybody’s picture

Status: Needs review » Needs work

2 fail?

Anybody’s picture

Suuper nice @Grevil! Just some last comments added. Then this is RTBC! :)

Anybody’s picture

1 unresolved.

Grevil’s picture

Status: Needs work » Needs review

Done! Let's see if all tests succeed!

Anybody’s picture

Assigned: Grevil » Unassigned
Status: Needs review » Reviewed & tested by the community

All green! Yay :) RTBC!

  • 144c0a8 committed on 2.x
    Issue #3326503: image captcha form element, missing refresh button.
    
Grevil’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

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