1 system.module _system_sort_form_values_by_config($form, &$form_state, $inherited_bucket, $configs = array())

Sorts the $form_state['values'] array into CMI buckets by $form['#config'].

This function recursively searches the form to assign values from $form_state['values'] into specific CMI buckets. The top of $form must contain a $form['#config'] entry with the name of the default CMI bucket to use. If an element contains its own $form['#config'] entry, that CMI bucket name will be used for that element and any child elements in the form.

Parameters

$form: An associative array containing the structure of a portion of the form.

&$form_state: A keyed array containing the current state of the form.

$inherited_bucket: The name of the bucket to use if $form['#config'] is not set.

$configs: A keyed array that will contain the form values sorted by CMI bucket when the function returns. Defaults to an empty array.

Return value

Returns an array where the keys are the names of the CMI buckets (e.g.,: system.settings) and the values are key => value arrays of the settings for each bucket.

File

core/modules/system/system.module, line 4641
Configuration system that lets administrators modify the workings of the site.

Code

function _system_sort_form_values_by_config($form, &$form_state, $inherited_bucket, $configs = array()) {
  foreach (element_children($form) as $key) {
    $form_fragment = $form[$key];

    // Specific elements or groups of elements can specify a bucket.
    $bucket = empty($form_fragment['#config']) ? $inherited_bucket : $form_fragment['#config'];
    // Save this element, if the value is present.
    if (array_key_exists($key, $form_state['values'])) {
      $configs[$bucket][$key] = $form_state['values'][$key];
    }
    // Descend into subgroups.
    if (is_array($form_fragment) && count(element_children($form_fragment))) {
      $configs = _system_sort_form_values_by_config($form_fragment, $form_state, $bucket, $configs);
    }
  }
  return $configs;
}