function _cleantalk_form_alter in Anti Spam by CleanTalk 8.4
Same name and namespace in other branches
- 8 cleantalk.module \_cleantalk_form_alter()
- 8.3 cleantalk.module \_cleantalk_form_alter()
- 7.5 cleantalk.module \_cleantalk_form_alter()
- 7 cleantalk.module \_cleantalk_form_alter()
- 7.2 cleantalk.module \_cleantalk_form_alter()
- 7.4 cleantalk.module \_cleantalk_form_alter()
- 9.1.x cleantalk.module \_cleantalk_form_alter()
Cleantalk inner function - alters needed form.
1 call to _cleantalk_form_alter()
- cleantalk_form_alter in ./
cleantalk.module - Implements hook_form_BASE_FORM_ID_alter()
File
- ./
cleantalk.module, line 340
Code
function _cleantalk_form_alter(&$form, &$form_state, $form_id) {
$url_exclusion = explode(",", \Drupal::config('cleantalk.settings')
->get('cleantalk_url_exclusions'));
if (is_array($url_exclusion) && count($url_exclusion)) {
$check_type = \Drupal::config('cleantalk.settings')
->get('cleantalk_url_regexp');
foreach ($url_exclusion as $key => $value) {
if (!empty($value)) {
if ($check_type == 1) {
// If RegExp
if (@preg_match('/' . trim($value) . '/', $_SERVER['REQUEST_URI'])) {
return;
}
}
else {
if (strpos($_SERVER['REQUEST_URI'], $value) !== false) {
// Simple string checking
return;
}
}
}
}
}
if (\Drupal::currentUser()
->hasPermission('access administration menu')) {
return;
}
if (\Drupal::config('cleantalk.settings')
->get('cleantalk_link') && $form_id != 'search_form' && $form_id != 'user_login_form' && $form_id != 'search_block_form') {
$form['cleantalk_link'] = array(
'#type' => 'item',
'#markup' => t("<a href='https://cleantalk.org/drupal-anti-spam-module-wo-captcha'>Drupal spam</a> blocked by CleanTalk."),
'#required' => FALSE,
'#weight' => 999,
);
}
if ($form_id == 'user_register_form') {
$form['#validate'][] = 'cleantalk_validate_register';
}
else {
if (preg_match('|comment(.*?)_form|', $form_id)) {
$form['#validate'][] = 'cleantalk_validate_comment';
}
if (preg_match('|contact(.*?)_form|', $form_id)) {
$form['#validate'][] = 'cleantalk_validate_contact_message';
}
if (preg_match('|webform(.*?)_form|', $form_id)) {
$form['#validate'][] = 'cleantalk_validate_webform';
}
if (preg_match('|node_forum(.*?)_form|', $form_id)) {
$form['#validate'][] = 'cleantalk_validate_forum_topic';
}
if ($form_id == 'search_form' || $form_id == 'search_block_form') {
// No special handler is set
// $form['#validate'][] = 'cleantalk_validate_search_form';
}
}
}