public function FileFeatureForm::validateForm in Ubercart 8.4
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
- uc_file/
src/ Form/ FileFeatureForm.php, line 247
Class
- FileFeatureForm
- Creates or edits a file feature for a product.
Namespace
Drupal\uc_file\FormCode
public function validateForm(array &$form, FormStateInterface $form_state) {
// Ensure this is actually a file we control...
if (!\Drupal::database()
->query('SELECT fid FROM {uc_files} WHERE filename = :name', [
':name' => $form_state
->getValue('uc_file_filename'),
])
->fetchField()) {
$form_state
->setErrorByName('uc_file_filename', $this
->t('%file is not a valid file or directory inside file download directory.', [
'%file' => $form_state
->getValue('uc_file_filename'),
]));
}
// If any of our overrides are set, then we make sure they make sense.
if ($form_state
->getValue('download_override') && $form_state
->getValue('download_limit_number') < 0) {
$form_state
->setErrorByName('download_limit_number', $this
->t('A negative download limit does not make sense. Please enter a positive integer, or leave empty for no limit.'));
}
if ($form_state
->getValue('location_override') && $form_state
->getValue('download_limit_addresses') < 0) {
$form_state
->setErrorByName('download_limit_addresses', $this
->t('A negative IP address limit does not make sense. Please enter a positive integer, or leave empty for no limit.'));
}
if ($form_state
->getValue('time_override') && $form_state
->getValue('duration_granularity') != 'never' && $form_state
->getValue('duration_qty') < 1) {
$form_state
->setErrorByName('duration_qty', $this
->t('You set the granularity (%gran), but you did not set how many. Please enter a positive non-zero integer.', [
'%gran' => $form_state
->getValue('duration_granularity') . '(s)',
]));
}
}