Commit 1ece9427 authored by sonvir249's avatar sonvir249 Committed by elachlan

Issue #2913295 by sonvir249: #access=FALSE should disable validation

parent 6f472b65
......@@ -45,6 +45,8 @@ define('CAPTCHA_STATUS_EXAMPLE', 2);
define('CAPTCHA_DEFAULT_VALIDATION_CASE_SENSITIVE', 0);
define('CAPTCHA_DEFAULT_VALIDATION_CASE_INSENSITIVE', 1);
// Default captcha field access.
define('CAPTCHA_FIELD_DEFAULT_ACCESS', 1);
/**
* Implements hook_help().
*/
......@@ -432,6 +434,11 @@ function captcha_validate($element, FormStateInterface &$form_state) {
->execute()
->fetchField();
// Bypass captcha validation if access attribute value is false.
if (empty($captcha_info['access'])) {
return false;
}
// @todo: what is the result when there is no entry for
// the captcha_session? in D6 it was FALSE, what in D7?
if ($solution === FALSE) {
......
......@@ -155,12 +155,15 @@ class Captcha extends FormElement implements ContainerFactoryPluginInterface {
// useful in _captcha_get_posted_captcha_info().
// - $element['#captcha_info'], for post processing functions that do not
// receive a $form_state argument (e.g. the pre_render callback).
// Added a new access attribute,
// by default it will be true if access attribute not defined in a custom form.
$form_state->set('captcha_info', [
'this_form_id' => $this_form_id,
'posted_form_id' => $posted_form_id,
'captcha_sid' => $captcha_sid,
'module' => $captcha_type_module,
'captcha_type' => $captcha_type_challenge,
'access' => isset($element['#access']) ? $element['#access'] : CAPTCHA_FIELD_DEFAULT_ACCESS
]);
$element['#captcha_info'] = [
'form_id' => $this_form_id,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment