forked from chuva-inc/captcha
-
Notifications
You must be signed in to change notification settings - Fork 2
/
captcha.admin.inc
executable file
·50 lines (45 loc) · 1.42 KB
/
captcha.admin.inc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
/**
* @file
* Functionality and helper functions for CAPTCHA administration.
*/
/**
* Return an array with the available CAPTCHA types.
*
* For use as options array for a select form elements.
*
* @param bool $add_special_options
* If true: also add the 'default' option.
*
* @return array
* An associative array mapping "$module/$type" to
* "$type (from module $module)" with $module the module name
* implementing the CAPTCHA and $type the name of the CAPTCHA type.
*/
function _captcha_available_challenge_types($add_special_options = TRUE) {
$captcha_types = [];
if ($add_special_options) {
$captcha_types['default'] = t('Default challenge type');
}
// We do our own version of Drupal's module_invoke_all() here because
// we want to build an array with custom keys and values.
foreach (\Drupal::moduleHandler()->getImplementations('captcha') as $module) {
$result = call_user_func_array($module . '_captcha', ['list']);
if (is_array($result)) {
foreach ($result as $type) {
$captcha_types["$module/$type"] = t('@type (from module @module)', ['@type' => $type, '@module' => $module]);
}
}
}
return $captcha_types;
}
/**
* Helper function for generating an example challenge.
*/
function _captcha_generate_example_challenge($module, $type) {
return [
'#type' => 'captcha',
'#captcha_type' => $module . '/' . $type,
'#captcha_admin_mode' => TRUE,
];
}