You are here

function math_captcha_captcha in CAPTCHA Pack 8

Same name and namespace in other branches
  1. 5 math_captcha/math_captcha.module \math_captcha_captcha()
  2. 6 math_captcha/math_captcha.module \math_captcha_captcha()
  3. 7 math_captcha/math_captcha.module \math_captcha_captcha()

Implements hook_captcha().

File

math_captcha/math_captcha.module, line 21
Contains general functionality of the module.

Code

function math_captcha_captcha($op, $captcha_type = '') {
  switch ($op) {
    case 'list':
      return [
        'Math CAPTCHA',
      ];
    case 'generate':
      if ($captcha_type == 'Math CAPTCHA') {
        module_load_include('inc', 'math_captcha', 'math_captcha.challenge');

        // Get the available challenges.
        $enabled_challenges = _math_captcha_enabled_challenges();
        $challenges = array_filter($enabled_challenges);
        $challenge = $challenges[array_rand($challenges)];
        $form_item = call_user_func("_math_captcha_{$challenge}_challenge");
        \Drupal::service('page_cache_kill_switch')
          ->trigger();
        return $form_item;
      }
      break;
  }
}