You are here

function _webform_optionsmarkup_options_to_text in Webform Options Markup 7.2

Same name and namespace in other branches
  1. 7 components/webform_optionsmarkup.inc \_webform_optionsmarkup_options_to_text()

Convert an array of options into text.

File

components/webform_optionsmarkup.inc, line 708
Webform component that allows markup in checkbox and radio options.

Code

function _webform_optionsmarkup_options_to_text($options) {
  $output = '';
  $previous_key = FALSE;
  foreach ($options as $key => $value) {

    // Groups and Options with markup.
    if (is_array($value)) {

      // Groups.
      if (!$value['title']) {
        $output .= '<' . $key . '>' . "\n";
        foreach ($value as $subkey => $subvalue) {
          $output .= $subkey . '|' . $subvalue['title'] . '|' . $subvalue['desc'] . "\n";
        }
      }
      else {

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

        // Skip empty rows.
        if ($options[$key] !== '') {
          $output .= $key . '|' . $value['title'] . '|' . $value['desc'] . "\n";
        }
      }
    }
    else {

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

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