public function KmlImporter::validateForm in farmOS 2.x
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
- modules/
core/ import/ modules/ kml/ src/ Form/ KmlImporter.php, line 274
Class
- KmlImporter
- Provides a form for importing KML placemarks as land assets.
Namespace
Drupal\farm_import_kml\FormCode
public function validateForm(array &$form, FormStateInterface $form_state) {
// Only validate if the file has been parsed.
if (!$form_state
->getValue('parsed')) {
return;
}
$assets = $form_state
->getValue('assets', []);
$confirmed_assets = array_filter($assets, function ($asset) {
return !empty($asset['confirm']);
});
// Set an error if no assets are selected to be created.
if (empty($confirmed_assets)) {
$form_state
->setErrorByName('submit', $this
->t('At least one asset must be created.'));
}
}