You are here

public function WebformEntityReferenceTrait::validateConfigurationForm in Webform 6.x

Same name and namespace in other branches
  1. 8.5 src/Plugin/WebformElement/WebformEntityReferenceTrait.php \Drupal\webform\Plugin\WebformElement\WebformEntityReferenceTrait::validateConfigurationForm()
1 method overrides WebformEntityReferenceTrait::validateConfigurationForm()
WebformTermReferenceTrait::validateConfigurationForm in src/Plugin/WebformElement/WebformTermReferenceTrait.php

File

src/Plugin/WebformElement/WebformEntityReferenceTrait.php, line 626

Class

WebformEntityReferenceTrait
Provides an 'entity_reference' trait.

Namespace

Drupal\webform\Plugin\WebformElement

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 auto_create and include_anonymous into boolean.
  if (isset($values['selection_settings']['auto_create'])) {
    $values['selection_settings']['auto_create'] = (bool) $values['selection_settings']['auto_create'];
  }
  if (isset($values['selection_settings']['include_anonymous'])) {
    $values['selection_settings']['include_anonymous'] = (bool) $values['selection_settings']['include_anonymous'];
  }
  $form_state
    ->setValues($values);
}