From dcc351e61de6bb04ef103ba168938ac78ca9fd08 Mon Sep 17 00:00:00 2001 From: Huong Nguyen Date: Mon, 14 Aug 2023 16:01:40 +0700 Subject: [PATCH] MDL-53368 recaptcha: Implement compact display mode --- lib/recaptchalib_v2.php | 8 ++++++-- lib/upgrade.txt | 2 ++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/recaptchalib_v2.php b/lib/recaptchalib_v2.php index 3e48e01c6ea..87f7063f34d 100644 --- a/lib/recaptchalib_v2.php +++ b/lib/recaptchalib_v2.php @@ -104,9 +104,10 @@ function recaptcha_lang($lang = null) { * @param string $apiurl URL for reCAPTCHA API * @param string $pubkey The public key for reCAPTCHA * @param string $lang Language to use. If not provided, get current language. + * @param bool $compactmode If true, use the compact widget. * @return string - The HTML to be embedded in the user's form. */ -function recaptcha_get_challenge_html($apiurl, $pubkey, $lang = null) { +function recaptcha_get_challenge_html($apiurl, $pubkey, $lang = null, bool $compactmode = false) { global $CFG, $PAGE; // To use reCAPTCHA you must have an API key. @@ -127,7 +128,10 @@ function recaptcha_get_challenge_html($apiurl, $pubkey, $lang = null) { $apicode .= "\n"; $return = html_writer::script($jscode, ''); - $return .= html_writer::div('', 'recaptcha_element', array('id' => 'recaptcha_element')); + $return .= html_writer::div('', 'recaptcha_element', [ + 'id' => 'recaptcha_element', + 'data-size' => ($compactmode ? 'compact' : 'normal'), + ]); $return .= $apicode; return $return; diff --git a/lib/upgrade.txt b/lib/upgrade.txt index 00b0dd1f3a4..a0eb3c45d45 100644 --- a/lib/upgrade.txt +++ b/lib/upgrade.txt @@ -90,6 +90,8 @@ being forced open in all behat tests. * New method login_captcha_enabled() is created to check whether the login captcha is enabled or not. * New method validate_login_captcha() is created to validate the login captcha. * A new parameter $loginrecaptcha has been added to the authenticate_user_login() to check whether the login captcha is needed to verify or not. The default value is false. +* A new parameter $compactmode has been added to the recaptcha_get_challenge_html() to define whether the reCaptcha element should be displayed in the compact mode or not. + Default value is false. === 4.2 ===