public function StyleswitcherStyleForm::validateForm in Style Switcher 3.0.x
Same name and namespace in other branches
- 8.2 src/Form/StyleswitcherStyleForm.php \Drupal\styleswitcher\Form\StyleswitcherStyleForm::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/ StyleswitcherStyleForm.php, line 128
Class
- StyleswitcherStyleForm
- Provides a form to add/edit a style.
Namespace
Drupal\styleswitcher\FormCode
public function validateForm(array &$form, FormStateInterface $form_state) {
// Trim text values now, so submission handlers get them fully validated.
// No need to trim name, because it's validated by a machine-name pattern.
$form_state
->setValueForElement($form['label'], trim($form_state
->getValue('label')));
$path = $form_state
->getValue('path');
if ($path === '') {
// Set the path back to NULL.
$form_state
->setValueForElement($form['path'], NULL);
}
else {
$path = trim($path);
$form_state
->setValueForElement($form['path'], $path);
if (!is_file($path) && !UrlHelper::isExternal($path)) {
$form_state
->setErrorByName('path', $this
->t('Stylesheet file %path does not exist.', [
'%path' => $path,
]));
}
}
}