function _text_captcha_word_pool_validate_word_length in CAPTCHA Pack 8
Same name and namespace in other branches
- 5 text_captcha/text_captcha.inc \_text_captcha_word_pool_validate_word_length()
- 6 text_captcha/text_captcha.inc \_text_captcha_word_pool_validate_word_length()
- 7 text_captcha/text_captcha.inc \_text_captcha_word_pool_validate_word_length()
Validates word length.
Parameters
string $name: Field name.
array $words: Array of words.
int $minimum_length: Minimal length.
string $too_short_message: Message to be shown on validation.
\Drupal\Core\Form\FormStateInterface $form_state: Form state.
1 call to _text_captcha_word_pool_validate_word_length()
- _text_captcha_word_pool_validate in text_captcha/
text_captcha.module - Helper function for validating the word pool locale dependent.
File
- text_captcha/
text_captcha.module, line 142 - Contains general functionality for the module.
Code
function _text_captcha_word_pool_validate_word_length($name, array $words, $minimum_length, $too_short_message, FormStateInterface $form_state) {
$too_short = [];
foreach ($words as $word) {
if (count(_text_captcha_utf8_split($word)) < $minimum_length) {
$too_short[] = $word;
}
}
if (count($too_short)) {
$form_state
->setErrorByName($name, t($too_short_message, [
'@minimum_length' => $minimum_length,
'@words' => implode(', ', $too_short),
]));
}
}