captcha.admin.inc 1.21 KB
Newer Older
1
2
<?php

3
4
5
6
7
/**
 * @file
 * Functionality and helper functions for CAPTCHA administration.
 */

8
9
10
11
/**
 * Return an array with the available CAPTCHA types.
 *
 * For use as options array for a select form elements.
12
 *
13
 * @param bool $add_special_options
14
 *   If true: also add the 'default' option.
15
 *
16
17
18
19
 * @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.
20
 */
21
function _captcha_available_challenge_types($add_special_options = TRUE) {
22
  $captcha_types = [];
23
  if ($add_special_options) {
24
    $captcha_types['default'] = t('Default challenge type');
25
  }
Fabiano Sant'Ana's avatar
Fabiano Sant'Ana committed
26

27
28
  // We do our own version of Drupal's module_invoke_all() here because
  // we want to build an array with custom keys and values.
tonnosf's avatar
tonnosf committed
29
  foreach (\Drupal::moduleHandler()->getImplementations('captcha') as $module) {
30
    $result = call_user_func_array($module . '_captcha', ['list']);
31
32
    if (is_array($result)) {
      foreach ($result as $type) {
33
34
35
36
        $captcha_types["$module/$type"] = t('@type (from module @module)', [
          '@type' => $type,
          '@module' => $module,
        ]);
37
38
39
40
41
      }
    }
  }
  return $captcha_types;
}