Problem/Motivation
Follow-up issue to https://www.drupal.org/project/turnstile/issues/3330710 and to https://www.drupal.org/project/turnstile/issues/3505942
When loaded through Drupal dialog and with a challenge already in the page, the js command is not thrown.
I think the detection in TurnstileAjaxSubscriber is not correct / covering all use cases.
Turnstile js files are loaded, but the challenge is not rendered.
Steps to reproduce
- Install Turnstile
- Add a form on a region (bottom form in my case)
- Add a link to open a webform on a dialog
- Turnstile is not loaded/challenged (and throw an error when submitting "The answer you entered for the CAPTCHA was not correct.")
Proposed resolution
Change onResponse Turnstile detection to cover all response with turnstile library.
<?php
public function onResponse(ResponseEvent $event): void {
$response = $event->getResponse();
if ($response instanceof AjaxResponse) {
$attachments = $response->getAttachments();
if (!empty($attachments) && isset($attachments['library']) && !empty($attachments['library']) && in_array('turnstile/turnstile.remote', $attachments['library'])) {
$response->addCommand(new BaseCommand('turnstileRender', []));
}
}
}
?>Issue fork turnstile-3529743
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 #4
greatmatter commentedThanks, @nicodh! I've committed this to dev; I'd like to see it tested in multiple environments before giving it a release tag. None of our sites use it in this manner, so I don't have a good test for it.
Comment #5
filipnest commentedHi! We have a site that this is very much needed on and confirming the patch worked there. Not a modal but loading the form in via ajax when another non ajax form with it on was already on the page.
Comment #6
greatmatter commentedOk, we've released it.
Comment #7
greatmatter commented