You are here

public function YamlFormEntityReferenceTrait::validateConfigurationForm in YAML Form 8

File

src/Plugin/YamlFormElement/YamlFormEntityReferenceTrait.php, line 515

Class

YamlFormEntityReferenceTrait
Provides an 'entity_reference' trait.

Namespace

Drupal\yamlform\Plugin\YamlFormElement

Code

public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
  parent::validateConfigurationForm($form, $form_state);
  $values = $form_state
    ->getValues();
  if (isset($values['selection_settings']['target_bundles']) && empty($values['selection_settings']['target_bundles'])) {
    unset($values['selection_settings']['target_bundles']);
  }
  if (isset($values['selection_settings']['sort']['field']) && $values['selection_settings']['sort']['field'] == '_none') {
    unset($values['selection_settings']['sort']);
  }

  // Convert include_anonymous into boolean.
  if (isset($values['selection_settings']['include_anonymous'])) {
    $values['selection_settings']['include_anonymous'] = (bool) $values['selection_settings']['include_anonymous'];
  }
  $form_state
    ->setValues($values);
}