Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
No script element
<noscript>
<style>form.antibot * :not(.antibot-message) { display: none !important; }</style>
</noscript>
is previewed on all pages, but we need it only on pages with antibot protected forms.
Comment | File | Size | Author |
---|---|---|---|
#17 | functionalJavascript.png | 26.34 KB | Tauany Bueno |
#17 | functionalTests.png | 64.49 KB | Tauany Bueno |
#17 | message_after.png | 65.49 KB | Tauany Bueno |
#7 | 3195229_after.png | 176.58 KB | hmendes |
#7 | 3195229_before.png | 179.2 KB | hmendes |
Issue fork antibot-3195229
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 #3
sakiland CreditAttribution: sakiland as a volunteer commentedWe need to write an automated test to cover this functionality.
Comment #4
gaurav.kapoor CreditAttribution: gaurav.kapoor at Axelerant for Drupal India Association commentedComment #6
paulocsAdded tests to it.
Comment #7
hmendes CreditAttribution: hmendes at CI&T commentedTested the MR and it worked perfectly, attaching prints from before and after the MR.
Comment #8
gaurav.kapoor CreditAttribution: gaurav.kapoor at Axelerant for Drupal India Association commentedThis is working for me, but the issue is the usage of the drupal_static function which will be marked deprecated soon (Check https://www.drupal.org/project/drupal/issues/2260187) and wouldn't exist in Drupal 10. Let's try to resolve it in a different way. Thanks for adding the test though.
Comment #9
sakiland CreditAttribution: sakiland as a volunteer commentedThank you @hmendes, @paulocs, @gaurav.kapoor for the help. I will try to find some better solution for this.
Comment #10
sakiland CreditAttribution: sakiland as a volunteer commentedI've removed usage of the
drupal_static
method, and set variable as global.All tests for Drupal 8 passed, but there are 2 failed tests for Drupal 9.2 (ignore test suite run on PHP 7.3 & MariaDB 10.2.7 D9.2, I've chosen unsupported MariaDB version for Drupal 9, my mistake)
I cannot discover why 2 tests failed for Drupal 9, any help would be great. Thank you!
Comment #11
gaurav.kapoor CreditAttribution: gaurav.kapoor at Axelerant for Drupal India Association commentedI am not sure if using global is also the right solution here. Marking needs work to get more feedback around it and check why tests are failing.
Comment #12
beatrizrodriguesI will check why the tests are failing
Comment #13
gaurav.kapoor CreditAttribution: gaurav.kapoor at Axelerant for Drupal India Association commentedThanks, @beatrizrodrigues. Do you have any feedback regarding the implementation by @sakiland in #9?
Comment #14
beatrizrodrigues@gaurav.kapoor I'm sorry, but I got really stuck at this issue. I spent a lot of time local testing the classes that was returning errors here, but i couldn't be able to understand why they are failing. Locally, the AntibotNoJavascriptTest and AntibotCacheTagsTest tests are returning "OK", only the AntibotJavascriptTest tests has a bad return. (I'm testing all in D9.2). It returns me:
I'm new here so I'm still learning how to deal with some problems I face it. So, I couldn't tell if it is a actual error or something is missing locally here. I wish I could solve this. I'm open to learn if anyone wants to share something about this issue.
Comment #15
gaurav.kapoor CreditAttribution: gaurav.kapoor at Axelerant for Drupal India Association commentedComment #16
Tauany Bueno CreditAttribution: Tauany Bueno at CI&T commentedhi! i'll work on it :)
Comment #17
Tauany Bueno CreditAttribution: Tauany Bueno at CI&T commentedI fixed some PHPCS errors, and also checked the tests and removed some deprecated functions. All functional tests were passing on my local environment, I'm just not really sure about the FunctionalJavascript (I'll attach some images). I'll leave the status as needs review, but i'd be happy to help fix any other problems that may appear.
Comment #19
Tauany Bueno CreditAttribution: Tauany Bueno at CI&T commentedHello!
I ended up committing to the wrong version of the module, so I made a new merge request to the right version (2.0.x0-dev) fixed some conflicts. All functional tests were passing on my local environment, I'm just not really sure about the FunctionalJavascript (see attached images). I'm leaving the status as needs review, I'm new to Drupal, so I'm still learning how to solve some problems, but I'd be more than happy to learn and help fix any other issue that might appear.
Comment #21
beatrizramos CreditAttribution: beatrizramos at CI&T commentedComment #22
damiaosj CreditAttribution: damiaosj at CI&T commentedHi! I'll review this one.
Comment #23
damiaosj CreditAttribution: damiaosj at CI&T commentedHi! I have made the review and talked directly with @beatrizramos to solve just one error that was showing in the PHPCS. We fixed it, and reviewed again and now everything is fine!
Due there's no errors or warnings, I'm changing the status to RTBC.
Comment #24
gaurav.kapoor CreditAttribution: gaurav.kapoor at Axelerant for Drupal India Association commentedLooking into this, let's try to get tests working as well.
Comment #25
gaurav.kapoor CreditAttribution: gaurav.kapoor at Axelerant for Drupal India Association commentedFew conversation still open in MR.
Comment #26
vishaljd CreditAttribution: vishaljd at Valuebound commentedComment #28
vishaljd CreditAttribution: vishaljd at Valuebound commentedComment #29
paulocsInstead of adding the library via hook_page_attachments, we can add it via JS but it will not allow other modules to edit the antibot style tag in the head element using the hook_page_attachments_alter. I think its the only way to avoid the noscript element to be rendered.
The hook_page_attachments is called before the hook_form_alter, so the way it's now, the noscript element is never rendered because the $_antibot_protection variable will be always NULL (unitialized).
We should evaluate if we add the noscript tag when the page is loaded via JS or if we keep the way it is (loading on all pages).
I'll address the comments added the the merge request 10.
MR11 doesn't have the changes to fix this issue. It has only code standard fix. We can keep our effort working on the branch of MR 10 (3195229-no-script-element).
Comment #30
paulocsKeep NW because of #29.