You are here

function _form_options_to_text in Options Element 6

Same name and namespace in other branches
  1. 7 options_element.inc \_form_options_to_text()

Logic function for form_options_to_text(). Do not call directly.

See also

form_options_to_text()

1 call to _form_options_to_text()
form_options_to_text in ./options_element.module
Create a textual representation of options from an array.

File

./options_element.inc, line 310
All logic for options_element form elements.

Code

function _form_options_to_text($options, $key_type) {
  $output = '';
  $previous_key = false;
  foreach ($options as $key => $value) {

    // Convert groups.
    if (is_array($value)) {
      $output .= '<' . $key . '>' . "\n";
      foreach ($value as $subkey => $subvalue) {
        $output .= ($key_type == 'mixed' || $key_type == 'numeric' || $key_type == 'custom' ? $subkey . '|' : '') . $subvalue . "\n";
      }
      $previous_key = $key;
    }
    else {

      // Exit out of any groups.
      if (isset($options[$previous_key]) && is_array($options[$previous_key])) {
        $output .= "<>\n";
      }

      // Skip empty rows.
      if ($options[$key] !== '') {
        if ($key_type == 'mixed' || $key_type == 'numeric' || $key_type == 'custom') {
          $output .= $key . '|' . $value . "\n";
        }
        else {
          $output .= $value . "\n";
        }
      }
      $previous_key = $key;
    }
  }
  return $output;
}