protected function GatsbyAdminForm::validateCsvUrl in Gatsby Live Preview & Incremental Builds 8
Same name and namespace in other branches
- 2.0.x src/Form/GatsbyAdminForm.php \Drupal\gatsby\Form\GatsbyAdminForm::validateCsvUrl()
Validates a URL that may be multi-value via commas.
Parameters
string $field_name: Field name.
\Drupal\Core\StringTranslation\TranslatableMarkup $error: Error message to show if invalid.
\Drupal\Core\Form\FormStateInterface $form_state: Form state.
1 call to GatsbyAdminForm::validateCsvUrl()
- GatsbyAdminForm::validateForm in src/
Form/ GatsbyAdminForm.php - Form validation handler.
File
- src/
Form/ GatsbyAdminForm.php, line 195
Class
- GatsbyAdminForm
- Defines a config form to store Gatsby configuration.
Namespace
Drupal\gatsby\FormCode
protected function validateCsvUrl(string $field_name, TranslatableMarkup $error, FormStateInterface $form_state) : void {
$urls = array_map('trim', explode(',', $form_state
->getValue($field_name)));
foreach ($urls as $url) {
if (strlen($url) > 0 and !filter_var($url, FILTER_VALIDATE_URL)) {
$form_state
->setErrorByName($field_name, $error);
}
}
}