public function HotjarAdminSettingsForm::validateForm in Hotjar 8
Same name and namespace in other branches
- 8.2 src/Form/HotjarAdminSettingsForm.php \Drupal\hotjar\Form\HotjarAdminSettingsForm::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/ HotjarAdminSettingsForm.php, line 184
Class
- HotjarAdminSettingsForm
- Configure Hotjar settings for this site.
Namespace
Drupal\hotjar\FormCode
public function validateForm(array &$form, FormStateInterface $form_state) {
parent::validateForm($form, $form_state);
// Trim some text values.
$form_state
->setValue('hotjar_account', trim($form_state
->getValue('hotjar_account')));
$form_state
->setValue('hotjar_snippet_version', trim($form_state
->getValue('hotjar_snippet_version')));
$form_state
->setValue('hotjar_pages', trim($form_state
->getValue('hotjar_pages')));
$form_state
->setValue('hotjar_roles', array_filter($form_state
->getValue('hotjar_roles')));
// Verify that every path is prefixed with a slash.
if ($form_state
->getValue('hotjar_visibility_pages') != 2) {
$pages = preg_split('/(\\r\\n?|\\n)/', $form_state
->getValue('hotjar_pages'));
foreach ($pages as $page) {
if (strpos($page, '/') !== 0 && $page !== '<front>') {
$form_state
->setErrorByName('hotjar_pages', $this
->t('Path "@page" not prefixed with slash.', [
'@page' => $page,
]));
// Drupal forms show one error only.
break;
}
}
}
}