You are here

function context_ui_item_display in Context 6

Same name and namespace in other branches
  1. 6.2 context_ui/context_ui.admin.inc \context_ui_item_display()

Generates an abbreviated list of items for display in the setter/getter UI.

1 call to context_ui_item_display()
theme_context_ui_form in context_ui/context_ui.admin.inc
Theme function for context_ui_form()

File

context_ui/context_ui.admin.inc, line 307

Code

function context_ui_item_display($type, $element) {

  // We're dealing with an item with options --
  // try to grab the display-friendly value
  $items = array();
  $title = l($element['#title'], $_GET['q'], array(
    'fragment' => $type,
  ));
  if (isset($element['#options'])) {
    if (isset($element['#default_value'])) {
      if (is_array($element['#default_value'])) {
        foreach ($element['#default_value'] as $k) {
          $items[] = $element['#options'][$k];
        }
      }
      else {
        if (is_string($element['#default_value']) && ($k = $element['#default_value'])) {
          if (!empty($element['#options'][$k])) {
            $items[] = $element['#options'][$k];
          }
          else {

            // Fallback to the actual value
            $items[] = $k;
          }
        }
      }
    }
    if (empty($items)) {
      $items[] = array(
        'data' => '',
        'class' => 'empty',
      );
    }
  }
  else {
    if (isset($element['#type']) && in_array($element['#type'], array(
      'textfield',
      'textarea',
    ))) {
      $items[] = !empty($element['#default_value']) ? $element['#default_value'] : array(
        'data' => '',
        'class' => 'empty',
      );
    }
  }
  $output = '';
  $output .= theme('item_list', $items, $title, 'ul', array(
    'id' => 'display-' . $type,
  ));
  return $output;
}