public function ImportForm::validateForm in Default Content Deploy 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/ ImportForm.php, line 113
Class
- ImportForm
- Config Form for run DCD deploy in Admin UI.
Namespace
Drupal\default_content_deploy\FormCode
public function validateForm(array &$form, FormStateInterface $form_state) {
$all_files = $this
->getRequest()->files
->get('files', []);
if (!empty($all_files['file'])) {
/** @var \Symfony\Component\HttpFoundation\File\UploadedFile $file_upload */
$file_upload = $all_files['file'];
$extension = $file_upload
->getClientOriginalExtension();
// Checking the extension.
if ($extension != 'gz') {
$form_state
->setErrorByName('file', $this
->t('The selected file %filename cannot be uploaded. Only files with the following extensions are allowed: %extensions.', [
'%filename' => $file_upload
->getClientOriginalName(),
'%extensions' => 'tar.gz',
]));
}
if ($file_upload
->isValid()) {
$form_state
->setValue('file', $file_upload
->getRealPath());
}
else {
$form_state
->setErrorByName('file', $this
->t('The file could not be uploaded.'));
}
}
}