public function DisableMessagesSettingsForm::validateForm in Disable Messages 8
Same name and namespace in other branches
- 2.x src/Form/DisableMessagesSettingsForm.php \Drupal\disable_messages\Form\DisableMessagesSettingsForm::validateForm()
Form validation handler.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Overrides FormBase::validateForm
File
- src/
Form/ DisableMessagesSettingsForm.php, line 141
Class
- DisableMessagesSettingsForm
- Provides a form for administering disable messages.
Namespace
Drupal\disable_messages\FormCode
public function validateForm(array &$form, FormStateInterface $form_state) {
global $_disable_messages_error, $_disable_messages_error_no;
$patterns = explode("\n", $form_state
->getValues()['disable_messages_ignore_patterns']);
// Override drupal error handler to handle the preg error here.
set_error_handler('_disable_messages_error_handler');
foreach ($patterns as $pattern) {
$pattern = preg_replace([
'/^\\s*/',
'/\\s*$/',
], '', $pattern);
try {
preg_match('/' . $pattern . '/', "This is a test string");
} catch (\Exception $e) {
}
if ($_disable_messages_error) {
$form_state
->setErrorByName('disable_messages_ignore_patterns', $this
->t('"@pattern" is not a valid regular expression. Preg error (@error_no) - @error', [
'@pattern' => $pattern,
'@error_no' => $_disable_messages_error_no,
'@error' => $_disable_messages_error,
]));
restore_error_handler();
return;
}
}
}