You are here

public static function WebformOptionsHelper::validateOptionValues in Webform 8.5

Same name and namespace in other branches
  1. 6.x src/Utility/WebformOptionsHelper.php \Drupal\webform\Utility\WebformOptionsHelper::validateOptionValues()

Validate options values by removing invalid option values.

Parameters

array $options: An associative array of options.

array $values: An indexed array of options values.

Return value

array An indexed array of options values with invalid options removed.

1 call to WebformOptionsHelper::validateOptionValues()
WebformSubmissionForm::checkPrepopulateDataValid in src/WebformSubmissionForm.php
Determine if element prepopulate data is valid.

File

src/Utility/WebformOptionsHelper.php, line 254

Class

WebformOptionsHelper
Helper class webform options based methods.

Namespace

Drupal\webform\Utility

Code

public static function validateOptionValues(array $options, array $values) {
  $flattened_options = OptGroup::flattenOptions($options) ?: [];
  foreach ($values as $index => $item) {
    if (!isset($flattened_options[$item])) {
      unset($values[$index]);
    }
  }
  return array_values($values);
}