public function CslStyleFileForm::validateForm in Bibliography & Citation 8
Same name and namespace in other branches
- 2.0.x src/Form/CslStyleFileForm.php \Drupal\bibcite\Form\CslStyleFileForm::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 CslStyleForm::validateForm
File
- src/
Form/ CslStyleFileForm.php, line 36
Class
- CslStyleFileForm
- Form for installing bibcite_csl_style entity from file.
Namespace
Drupal\bibcite\FormCode
public function validateForm(array &$form, FormStateInterface $form_state) {
if ($file = $this
->extractFile()) {
$content = file_get_contents($file
->getRealPath());
$csl = new Csl($content);
if ($csl
->validate()) {
$form_state
->setValue('csl', $content);
parent::validateForm($form, $form_state);
}
else {
$form_state
->setErrorByName('file', $this
->t('The uploaded file does not contain valid CSL.'));
}
}
else {
$form_state
->setErrorByName('file', $this
->t('The file could not be uploaded.'));
}
}