You are here

cookies_recaptcha.module in COOKiES Consent Management 1.0.x

File

modules/cookies_recaptcha/cookies_recaptcha.module
View source
<?php

/**
 * @file
 * Contains cookies_recaptcha.module.
 */
use Drupal\cookies\CookiesKnockOutService;

/**
 * Implements hook_captcha().
 */
function cookies_recaptcha_captcha($op, $captcha_type = '') {
  $doKo = CookiesKnockOutService::getInstance()
    ->doKnockOut();
  if ($doKo) {
    switch ($op) {
      case 'list':
        return [
          'reCAPTCHA',
        ];
      case 'generate':
        $captcha = recaptcha_captcha($op, 'reCAPTCHA');
        foreach ($captcha["form"]["recaptcha_widget"]["#attached"]["html_head"] as $key => $head_tag) {
          if (in_array('recaptcha_api', $head_tag)) {
            $captcha["form"]["recaptcha_widget"]["#attached"]["html_head"][$key][0]['#attributes'] += [
              'type' => 'application/json',
              'id' => 'cookies_recaptcha',
            ];
            $captcha["form"]["recaptcha_widget"]["#attached"]["library"][] = 'cookies_recaptcha/default';
            break;
          }
        }
        return $captcha;
    }
  }
}

Functions

Namesort descending Description
cookies_recaptcha_captcha Implements hook_captcha().