public function GatsbyAdminForm::validateForm 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::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/ GatsbyAdminForm.php, line 160
Class
- GatsbyAdminForm
- Defines a config form to store Gatsby configuration.
Namespace
Drupal\gatsby\FormCode
public function validateForm(array &$form, FormStateInterface $form_state) {
parent::validateForm($form, $form_state);
$this
->validateCsvUrl('server_url', $this
->t('Invalid Gatsby preview server URL.'), $form_state);
$this
->validateCsvUrl('preview_callback_url', $this
->t('Invalid Gatsby preview callback URL.'), $form_state);
$path_mapping = $form_state
->getValue('path_mapping');
try {
$map = PathMapping::parsePathMapping($path_mapping);
if (strlen(trim($path_mapping)) > 0 && count($map) === 0) {
// Unable to parse anything meaningful from the path mapping.
$form_state
->setErrorByName('path_mapping', $this
->t('Invalid preview server path mapping.'));
}
} catch (\Error $e) {
// Parsing the path mapping caused a PHP Error.
$form_state
->setErrorByName('path_mapping', $this
->t('Invalid preview server path mapping.'));
}
$incremental_build_url = $form_state
->getValue('incrementalbuild_url');
if (strlen($incremental_build_url) > 0 and !filter_var($incremental_build_url, FILTER_VALIDATE_URL)) {
$form_state
->setErrorByName('incrementalbuild_url', $this
->t('Invalid incremental build URL.'));
}
}