public function LinkCheckerAdminSettingsForm::validateForm in Link checker 8
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/ LinkCheckerAdminSettingsForm.php, line 425
Class
- LinkCheckerAdminSettingsForm
- Configure Linkchecker settings for this site.
Namespace
Drupal\linkchecker\FormCode
public function validateForm(array &$form, FormStateInterface $form_state) {
parent::validateForm($form, $form_state);
$form_state
->setValue('linkchecker_disable_link_check_for_urls', trim($form_state
->getValue('linkchecker_disable_link_check_for_urls')));
$form_state
->setValue('linkchecker_ignore_response_codes', trim($form_state
->getValue('linkchecker_ignore_response_codes')));
$ignore_response_codes = preg_split('/(\\r\\n?|\\n)/', $form_state
->getValue('linkchecker_ignore_response_codes'));
foreach ($ignore_response_codes as $ignore_response_code) {
if (!$this->linkCheckerResponseCodes
->isValid($ignore_response_code)) {
$form_state
->setErrorByName('linkchecker_ignore_response_codes', $this
->t('Invalid response code %code found.', [
'%code' => $ignore_response_code,
]));
}
}
// Prevent the removal of RFC documentation domains. This are the official
// and reserved documentation domains and not "example" hostnames!
$linkchecker_disable_link_check_for_urls = array_filter(preg_split('/(\\r\\n?|\\n)/', $form_state
->getValue('linkchecker_disable_link_check_for_urls')));
$linkchecker_reserved_documentation_domains = "example.com\nexample.net\nexample.org";
$form_state
->setValue('linkchecker_disable_link_check_for_urls', implode("\n", array_unique(array_merge(explode("\n", $linkchecker_reserved_documentation_domains), $linkchecker_disable_link_check_for_urls))));
// Validate impersonation user name.
$linkchecker_impersonate_account = user_load_by_name($form_state
->getValue('linkchecker_impersonate_account'));
// @TODO: Cleanup
// if (empty($linkchecker_impersonate_account->id())) {
if ($linkchecker_impersonate_account && empty($linkchecker_impersonate_account
->id())) {
$form_state
->setErrorByName('linkchecker_impersonate_account', $this
->t('User account %name cannot found.', [
'%name' => $form_state
->getValue('linkchecker_impersonate_account'),
]));
}
}