public function AvatarGeneratorForm::validateForm in Avatar Kit 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/ AvatarGeneratorForm.php, line 115
Class
- AvatarGeneratorForm
- Form controller for avatar generator plugin instances.
Namespace
Drupal\avatars\FormCode
public function validateForm(array &$form, FormStateInterface $form_state) {
/** @var \Drupal\avatars\AvatarGeneratorInterface $avatar_generator */
$avatar_generator = $this
->getEntity();
if ($avatar_generator
->isNew()) {
// Add a plugin ID so default plugin config will be added when saved.
$avatar_generator = AvatarGenerator::create([
'id' => $form_state
->getValue('id'),
'label' => $form_state
->getValue('label'),
'plugin' => $form_state
->getValue('plugin'),
]);
$this
->setEntity($avatar_generator);
}
else {
$settings = (new FormState())
->setValues($form_state
->getValue('settings', []));
$avatar_generator
->getPlugin()
->validateConfigurationForm($form, $settings);
$form_state
->setValue('settings', $settings
->getValues());
}
}