You are here

public static function YamlFormExcludedBase::validateYamlFormExcluded in YAML Form 8

Validates a tablelselect element.

File

src/Element/YamlFormExcludedBase.php, line 67

Class

YamlFormExcludedBase
Provides a base form element for form excluded elements and columns.

Namespace

Drupal\yamlform\Element

Code

public static function validateYamlFormExcluded(array &$element, FormStateInterface $form_state, &$complete_form) {
  $value = array_filter($element['tableselect']['#value']);

  // Converted value to excluded elements.
  $options = array_keys($element['tableselect']['#options']);
  $excluded = array_diff($options, $value);

  // Unset tableselect and set the element's value to excluded.
  $form_state
    ->setValueForElement($element['tableselect'], NULL);
  $form_state
    ->setValueForElement($element, array_combine($excluded, $excluded));
}