MDL-53368 recaptcha: Implement compact display mode

This commit is contained in:
Huong Nguyen 2023-08-14 16:01:40 +07:00
parent 753fd18d1b
commit dcc351e61d
No known key found for this signature in database
GPG Key ID: 40D88AB693A3E72A
2 changed files with 8 additions and 2 deletions

View File

@ -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 .= "</script>\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;

View File

@ -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 ===