You are here

public static function OptionsBase::validateMultipleOptions in Webform 6.x

Same name and namespace in other branches
  1. 8.5 src/Plugin/WebformElement/OptionsBase.php \Drupal\webform\Plugin\WebformElement\OptionsBase::validateMultipleOptions()

Form API callback. Remove unchecked options from value array.

File

src/Plugin/WebformElement/OptionsBase.php, line 693

Class

OptionsBase
Provides a base 'options' element.

Namespace

Drupal\webform\Plugin\WebformElement

Code

public static function validateMultipleOptions(array &$element, FormStateInterface $form_state, array &$completed_form) {
  $values = $element['#value'] ?: [];

  // Filter unchecked/unselected options whose value is 0.
  $values = array_filter($values, function ($value) {
    return $value !== 0;
  });
  $values = array_values($values);
  $form_state
    ->setValueForElement($element, $values);
}