You are here

function theme_webform_display_optionsmarkup in Webform Options Markup 7.2

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

Format the text output for this component.

1 theme call to theme_webform_display_optionsmarkup()
_webform_display_optionsmarkup in components/webform_optionsmarkup.inc
Implements _webform_display_component().

File

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

Code

function theme_webform_display_optionsmarkup($variables) {
  $element = $variables['element'];

  // Flatten the list of options so we can get values easily. These options
  // may be translated by hook_webform_display_component_alter().
  $options = array();
  foreach ($element['#options'] as $key => $value) {
    if (is_array($value) and !$value['title']) {
      foreach ($value as $subkey => $subvalue) {
        $options[$subkey] = $subvalue['title'];
      }
    }
    else {
      $options[$key] = $value['title'];
    }
  }
  $items = array();
  if ($element['#multiple']) {
    foreach ((array) $element['#value'] as $option_value) {
      if ($option_value !== '') {

        // Administer provided values.
        if (isset($options[$option_value])) {
          $items[] = $element['#format'] == 'html' ? webform_optionsmarkup_filter_content($options[$option_value]) : $options[$option_value];
        }
      }
    }
  }
  else {
    if (isset($element['#value'][0]) && $element['#value'][0] !== '') {

      // Administer provided values.
      if (isset($options[$element['#value'][0]])) {
        $items[] = $element['#format'] == 'html' ? webform_optionsmarkup_filter_content($options[$element['#value'][0]]) : $options[$element['#value'][0]];
      }
    }
  }
  if ($element['#format'] == 'html') {
    $output = count($items) > 1 ? theme('item_list', array(
      'items' => $items,
    )) : (isset($items[0]) ? $items[0] : ' ');
  }
  else {
    if (count($items) > 1) {
      foreach ($items as $key => $item) {
        $items[$key] = ' - ' . $item;
      }
      $output = implode("\n", $items);
    }
    else {
      $output = isset($items[0]) ? $items[0] : ' ';
    }
  }
  return $output;
}