You are here

public static function YamlFormHelper::cleanupFormStateValues in YAML Form 8

Cleanup form state values.

Parameters

array $values: An array of form state values.

array $keys: (optional) An array of custom keys to be removed.

Return value

array The values without default keys like 'form_build_id', 'form_token', 'form_id', 'op', 'actions', etc...

1 call to YamlFormHelper::cleanupFormStateValues()
YamlFormHelperTest::testCleanupFormStateValues in tests/src/Unit/YamlFormHelperTest.php
Tests YamlFormHelper with YamlFormHelper::cleanupFormStateValues().

File

src/Utility/YamlFormHelper.php, line 22

Class

YamlFormHelper
Helper class form based methods.

Namespace

Drupal\yamlform\Utility

Code

public static function cleanupFormStateValues(array $values, array $keys = []) {

  // Remove default FAPI values.
  unset($values['form_build_id'], $values['form_token'], $values['form_id'], $values['op']);

  // Remove any objects.
  foreach ($values as $key => $value) {
    if (is_object($value)) {
      unset($values[$key]);
    }
  }

  // Remove custom keys.
  foreach ($keys as $key) {
    unset($values[$key]);
  }
  return $values;
}