public static function SimpleReCaptchaFormManager::formIdInList in Simple Google reCAPTCHA 8
Check whether the needle is in the haystack.
Parameters
string $needle: The needle which is checked.
string[] $haystack: A list of identifiers to determine whether $needle is in it.
Return value
bool True if the needle is in the haystack.
2 calls to SimpleReCaptchaFormManager::formIdInList()
- SimpleReCaptchaFormManagerTest::testFormIdInList in tests/
src/ Unit/ SimpleReCaptchaFormManagerTest.php - Test the formIdInList().
- simple_recaptcha_form_alter in ./
simple_recaptcha.module - Implements hook_form_alter().
File
- src/
SimpleReCaptchaFormManager.php, line 304
Class
- SimpleReCaptchaFormManager
- Provides helper service used to attach reCaptcha to forms.
Namespace
Drupal\simple_recaptchaCode
public static function formIdInList($needle, array $haystack) {
// Prepare the haystack for regex matching by quoting all regex symbols and
// replacing back the original '*' with '.*' to allow it to catch all.
$haystack = array_map(function ($line) {
return str_replace('\\*', '.*', preg_quote($line, '/'));
}, $haystack);
foreach ($haystack as $line) {
if (preg_match('/^' . $line . '$/', $needle)) {
return TRUE;
}
}
return FALSE;
}