public function SiteSettingReplicateForm::validateForm in Site Settings and Labels 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/ SiteSettingReplicateForm.php, line 164
Class
- SiteSettingReplicateForm
- Class SiteSettingReplicateForm.
Namespace
Drupal\site_settings\FormCode
public function validateForm(array &$form, FormStateInterface $form_state) {
parent::validateForm($form, $form_state);
if ($existing = $this->entityTypeManager
->getStorage('site_setting_entity_type')
->loadMultiple()) {
$values = $form_state
->getValues();
foreach ($values['new_settings'] as $key => $setting) {
// Skip if all empty and not first row.
if ($key > 0 && empty($setting['machine_name']) && empty($setting['label']) && empty($setting['fieldset'])) {
continue;
}
// Double check that all 3 are filled in if any 1 is.
if (empty($setting['machine_name'])) {
$form_state
->setErrorByName('new_settings][' . $key . '][machine_name', $this
->t('Please enter a machine name'));
}
if (empty($setting['label'])) {
$form_state
->setErrorByName('new_settings][' . $key . '][label', $this
->t('Please enter a label'));
}
if (empty($setting['fieldset'])) {
$form_state
->setErrorByName('new_settings][' . $key . '][fieldset', $this
->t('Please enter a fieldset'));
}
}
}
}