Does a way exist to modify the captcha_widgets captcha_refresh_link text? The property corresponding to this is protected and I'm not sure what approach I can take to override it. I could do something wonky through JavaScript, but I'd prefer to avoid that if possible.
To be clear, the text I'm referring to is as follows:
"Get new captcha!"
I'd like to change that to something else. Can that be done either in TWIG or else via some sort of preprocess function?
| Comment | File | Size | Author |
|---|---|---|---|
| #8 | captcha.png | 47.4 KB | dravenk |
Issue fork captcha-3301409
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
Comment #2
wolf_22 commentedThink I figured it out:
1.) Create an overrides module (i.e. - whatever.module file).
2.) Inside < YOUR MODULE >_captcha_alter($form, $form_state){}, include the following code:
3.) Clear the cache and refresh a page that has an image captcha. The new text should be visible now.
Hope this helps.
Comment #3
dravenkI created a custom form and added the image captcha. Unfortunately, my attempts to change the text of the Refresh button following the comment above were unsuccessful. Anyway, thanks very much @Wolf_22 for sharing. My customer asked me to modify Captch element titles and descriptions, etc. I think there should be an easy way to change the text content of the element. For example, the Challenge Description in the settings.
Comment #4
dravenkComment #6
dravenkComment #7
wolf_22 commenteddravenk, make sure you included all the CAPTCHA elements inside the markup that the overall form requires as many elements have to be used within the TWIG file to reach functional parity. (And obviously, clear the cache if you make any changes to your override file before testing things.)
Here's my complete TWIG file that I made for my CAPTCHA implementation, which I plopped into my theme's "templates" folder at /sites/all/themes//templates/user-login-form.html.twig:
The biggest pain in all this was figuring out which TWIG elements / objects I needed to reference inside this override file. I can't even remember how I learned which ones I needed to use, but what I have here works for me. Hope it helps.
Comment #8
dravenkHi,@Wolf_22. You just need to apply the patch and goto
/admin/config/people/captcha/image_captcha, then you can see the settings form.Comment #9
anybodyComment #10
anybodyComment #11
anybodyLooks very close to #3250708: Allow altering of CAPTCHA from other modules. Please note, that this is specific to the image captcha module, so perhaps that submodule could also be improved to use a twig file instead of raw form markup, as we've done it for CAPTCHA in #3314766: [2.x] Improve the CAPTCHA form markup and use twig files for more flexibility, where possible. But that should be a separate issue then, please.
Comment #12
anybodyComment #13
grevil commentedThere is no further development inside 8.x-1.x, setting this issue to 2.x.
Comment #14
grevil commentedTested and reviewed! Please have a final look at the Form text! :)
Comment #15
grevil commentedComment #16
anybodyNice @Grevil!
RTBC in general, just two points:
1. We should also have 2 tests for this: For the general functionality (a) detecting the text and clicking the link with the expected AJAX HTTP Status result and (b) checking the text change)
2. What do you think about "I can not read this" as default label?
You may decide to solve this here or as follow-up.
Comment #17
grevil commented@Anybody:
1. Let's create a minor follow up issue for this.
2. I think "Reload Captcha" is clearer, with a link text of "I can not read this", I wouldn't expect the captcha to reload as a user.
Comment #19
anybodybetter the other way around then. Or just leave as - is. You decide. Thanks! :)
Comment #20
designerada commentedHi,
I was able to accomplish this with CSS:
This solution isn't accessible for screen readers, but image captchas aren't accessible anyway, and I believe an audio option is in the works.
Comment #21
anybodyThanks @designerada,
this shows the text should be configurable in the Image Captcha settings. So we should add that @Grevil. :) Just as you wrote.