diff --git a/README.md b/README.md index 61f7cf8..771e737 100755 --- a/README.md +++ b/README.md @@ -83,3 +83,9 @@ MAINTAINERS Supporting organizations: * Chuva Inc. - https://www.drupal.org/chuva-inc + +DEVELOPMENT +------------- + You can disable captcha in your local or test environment by adding the + following line to settings.php: + $settings['disable_captcha'] = TRUE; diff --git a/captcha.module b/captcha.module index ce37c3f..4fcd204 100755 --- a/captcha.module +++ b/captcha.module @@ -18,6 +18,7 @@ use Drupal\Core\Render\Element; use Drupal\Core\Render\Markup; use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\Url; +use Drupal\Core\Site\Settings; /** * Constants for CAPTCHA persistence. @@ -287,6 +288,22 @@ function captcha_form_alter(array &$form, FormStateInterface $form_state, $form_ '#markup' => '
' . t('Most CAPTCHA methods will disable the caching of pages that contain a CAPTCHA element. Check the different implementations to know more about how it affects caching.') . '
', ]; } + + // Disable captcha if override is set. + if (Settings::get('disable_captcha', FALSE) === TRUE) { + $override_notice = [ + '#type' => 'html_tag', + '#tag' => 'strong', + '#value' => t('Captcha override is activated.'), + ]; + if (isset($form['elements']['captcha'])) { + $form['elements']['captcha'] = $override_notice; + } + if (isset($form['captcha'])) { + $form['captcha'] = $override_notice; + } + } + } /**