Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Open sidebar
drupal.org
captcha
Commits
e574e9bb
Commit
e574e9bb
authored
Oct 08, 2019
by
Fabiano Sant'Ana
Browse files
Issue #3086495 by wundo: Add CaptchaService
parent
14e46a11
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
46 additions
and
0 deletions
+46
-0
src/Service/CaptchaService.php
src/Service/CaptchaService.php
+46
-0
No files found.
src/Service/CaptchaService.php
0 → 100644
View file @
e574e9bb
<?php
namespace
Drupal\captcha\Service
;
/**
* Helper service for CAPTCHA module.
*/
class
CaptchaService
{
/**
* 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.
*/
public
function
getAvailableChallengeTypes
(
$add_special_options
=
TRUE
)
{
$challenges
=
[];
if
(
$add_special_options
)
{
$challenges
[
'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
)
{
$challenges
[
"
$module
/
$type
"
]
=
t
(
'@type (from module @module)'
,
[
'@type'
=>
$type
,
'@module'
=>
$module
,
]);
}
}
}
return
$challenges
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment