Problem/Motivation
Main parts of the CAPTCHA 8.x-1.x module seem to be a port of the Drupal 7 CAPTCHA module, with quite similar implementation.
But since Drupal 8 form styling and overriding was improved a lot by using twig files for form elements where ever possible. Trying to reduce the need for hooks to theme Drupal forms (as it's bad for theme developers / designers).
Having a look at the resulting markup and the implementation, CAPTCHA didn't improve a lot here. The resulting markup, which is also used by CAPTCHA extending modules like
and other CAPTCHA types using hook_captcha() can also be improved.
In this task we should discuss two things:
1. How to better use twig files to replace the need for hooks and technical FAPI implementations for theming the CAPTCHA generate output
2. How to improve the currenct CAPTCHA output markup like for example:
- Add a class for the captcha type to the wrapper element
- Discuss if "details" is really a good choice for a required form element wrapper - I guess not ;)
- Make the "details" title configurable in the CAPTCHA settings with default: "CAPTCHA"
- Allow to change the order / alignment of the captcha elements, for example beside or below each other by CSS
- Don't use "CAPTCHA" as readable label in the frontend, most of the users have no idea what this means. So this is a useless label.
- #3258191: Surround the 'Challenge description' phrase with an html tag
- ...?
Steps to reproduce
Proposed resolution
Remaining tasks
User interface changes
API changes
Data model changes
| Comment | File | Size | Author |
|---|---|---|---|
| #26 | interdiff26.diff | 895 bytes | grevil |
Issue fork captcha-3314766
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
anybodyComment #3
anybodyComment #4
anybodyComment #5
anybodyComment #6
anybodyComment #7
anybodyComment #8
thomas.frobieterI think the very first thing to improve, should be the formatter CSS class on the wrapper, so the module styles / theme styles are able to address the differences.
Comment #9
thomas.frobieterComment #10
anybodyAdded:
This needs heavy rework, I'll take some time for a MR soon.
Comment #11
thomas.frobieterMy 2 cent about the markup and the details element:
I have no idea why anyone would have the CAPTCHA in a collapsed state, so the Details element doesn't make any sense for me. I wouldn't even add this as an option. If someone needs this, its easy to override the Twig file.
In my opinion, every single CAPTCHA element should dropped as variable to the Twig template. All Markup should live inside this template file.
And for sure, the text "Answer this question to verify that you are not a spam robot." needs a wrapper then.
Comment #13
anybodyOkay, made a first shot. Most of the points above have been addressed. Due to the markup changes, I think this would be a good point for creating a 2.x dev version.
@thomas.frobieter:
this and allowing to hide the descriptive label (which we had hidden in our custom css) would be a nice setting I guess?
Any ideas how we could add that and how the setting could be named and look like?
Comment #14
grevil commented@thomas.frobieter please have a look at the changes once again.
Comment #15
grevil commentedThese changes currently break the module with the following error:
After a quick google search I found out, that we use the correct sanitization syntax, so I am not sure why the filter can not be found. 🤔
But I have no experience with templates, so maybe @thomas.frobieter can have a look!
Comment #16
thomas.frobieterOh yeah, the use of the clean_class_array fiter was a mistake. This filter is n/a in Drupal Core, its a contrib module: https://www.drupal.org/docs/8/modules/twig-tools/sanitization-filters
I'll change this, give me a second.
Comment #17
grevil commentedThx! I'll have a second look tomorrow, but can already tell from the tests and a quick peek at my local captcha login form, that this definitely still needs work!
Comment #18
thomas.frobieter@anybody: TBH, this sounds very unnecessary to me. This would be a global setting? But the CAPTCHA appears in multiple forms, various widths .. so I don't know, seems useless if not configurable for each CAPTCHA instance.
I think we better should ensure a solid default layout, what is very flexible/responsive by default. So for example the image captcha: Image left, input & text right while theres enough width, Image above if not.
We can do this with CSS Grid or Flexbox very easily, so no need for setting, IMO.
Comment #19
anybodyVery good idea! Yes please :)
Could you add this point for you?
Comment #20
grevil commentedOK, I couldn't finish this, as I had internal debugging problems with my dev environment.
The point is, that we need to additionally regard the "persistence" setting. This is considered in our FormElement, through "_captcha_required_for_user()" but not in our preprocess hook. So we need to get the required variables for the "_captcha_required_for_user()" function inside the preprocess hook and only render title and description if it returns true. Otherwise, if somebody already fulfilled the captcha but put in a wrong username, the captcha element and type is hidden, but the title and description are still being displayed.
Comment #21
anybodyThanks @Grevil, as just discussed, we should then simply put it into the form element.
Comment #22
grevil commentedOK all done! Please review!
@Anybody, especially check the update hook! For users which disabled the description, but still have a description string set, this update will delete that description. We could possibly notice the user about this, inside the update hook, but doubt anybody has important text inside the description worth noticing about.
Comment #23
grevil commentedComment #24
anybodyGreat work @Grevil and a super cool foundation for 2.x!
@Maintainer: As this contains BC for Theme overrides, please do not commit this to 8.x-1.x, instead create a 2.x from latest 8.x-1.x!
Comment #25
grevil commentedGood thing this wasn't merged yet! There is a BIG mistake using "delete($param)" for the old config entry instead of "clear($param)" which leads to deleting the ENTIRE config object instead of the single object entry!! I am really sorry for not testing this update hook beforehand (won't happen again).
Comment #26
grevil commentedFixed the issue, see attached interdiff.
Comment #27
anybody#18 is still open for @thomas.frobieter. @Thomas could you please assign this issue to you and add that part?
Or tell @Grevil how to do that?
As we're no maintainers (yet), I can't assign tasks to anyone else here.
Comment #28
anybodyCAPTCHA 2.x is up and running and we're Co-Maintainers now. Let's prepare this for the final commit!
Assigning this to @thomas.frobieter for #18.
Comment #29
grevil commentedRebased the branch on 2.x, Tests are all green locally.
Comment #30
thomas.frobieterI'll take care about this when if have the time.
Comment #31
grevil commentedRebased on current 2.x.
Comment #32
thomas.frobieterOkay I am ready with the image captcha styling. I've added a further wrapper in the form, to group the image and the reload link.
I've also done some cleanup, separated admin scripts & styles, created a libraries file + CSS for the captcha module itself.
The reload link now is a simple reload-icon instead text, to reduce clutter. Maybe this will need some accessibility love, but I think the image captcha itself is an accessibility nightmare, so ...
Comment #33
anybody@Grevil: This should then be reviewed and tested carefully for the many changes. If you see the need for tests somewhere, let's add them now!
Comment #34
grevil commentedRebased the branch! Twig file had a merge conflict 12 times, so I just fixed it afterwards :)
I'll check everything carefully now and see if anything broke!
Comment #35
grevil commentedTests are green and code looks good!
Although, we should definitely split such big issues in several smaller issues. Trying to review so many changes at once, can lead to overseeing problematic code.
Furthermore, trying to rebase this issue branch was an utter pain and leads to time-consuming actions. Note that rebasing means, that for every single commit done in dev, we have to reverse ALL commits done here, add the commit from dev and then ADD all commits from this issue branch again. Those are 31 commits now and counting. Meaning worst case, we could have 31 merge conflicts for EVERY SINGLE commit done in dev, before committing this!
So let's break it apart next time!
OK, on to the manual functionality test! :)
Comment #36
anybodyAgree!
So let's merge this :)
Comment #38
anybodyComment #41
grevil commentedJust a small reminder, as I couldn't remember, why 2.x is D10 only.
The reason behind this is, that besides the type hinting introduced in the newest Symfony release, used for D10, there were also method implementation changes (See https://git.drupalcode.org/project/captcha/-/merge_requests/47/diffs#1f6...).
That's why the newest release is D10 only! 👍