public function PhantomJSCaptureSettingsForm::validateForm in PhantomJS Capture 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/ PhantomJSCaptureSettingsForm.php, line 89
Class
- PhantomJSCaptureSettingsForm
- Class PhantomJSCaptureSettingsForm
Namespace
Drupal\phantomjs_capture\FormCode
public function validateForm(array &$form, FormStateInterface $form_state) {
$values = $form_state
->getValues();
// Check that PhantomJS exists.
if (!file_exists($values['binary'])) {
$form_state
->setError($form['binary'], $this
->t('The PhantomJS binary was not found at the location given.'));
}
// Check that destination can be created.
$destination = \Drupal::config('system.file')
->get('default_scheme') . '://' . $values['destination'];
if (!file_prepare_directory($destination, FILE_CREATE_DIRECTORY)) {
$form_state
->setError($form['destination'], t('The path was not writeable or could not be created.'));
}
// Check that capture script exists.
if (!file_exists($values['script'])) {
$form_state
->setError($form['script'], $this
->t('PhantomJS script was not found at the location given.'));
}
}