You are here

public function CaptchaService::getAvailableChallengeTypes in CAPTCHA 8

Return an array with the available CAPTCHA types.

For use as options array for a select form elements.

Parameters

bool $add_special_options: If true: also add the 'default' option.

Return value

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.

File

src/Service/CaptchaService.php, line 27

Class

CaptchaService
Helper service for CAPTCHA module.

Namespace

Drupal\captcha\Service

Code

public function getAvailableChallengeTypes(bool $add_special_options = TRUE) {
  $challenges = [];
  if ($add_special_options) {
    $challenges['default'] = $this
      ->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) {
        $challenges["{$module}/{$type}"] = $this
          ->t('@type (from module @module)', [
          '@type' => $type,
          '@module' => $module,
        ]);
      }
    }
  }
  return $challenges;
}