You are here

function context_ui_item_display in Context 6.2

Same name and namespace in other branches
  1. 6 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 398

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,
    'attributes' => array(
      'class' => 'context_ui-item-section-link',
    ),
  ));

  // Check for the extra help:
  if (isset($element['#help_topic']) && isset($element['#help_module']) && module_exists($element['#help_module'])) {
    $title = theme('advanced_help_topic', $element['#help_module'], $element['#help_topic']) . $title;
  }
  if (isset($element['#options'])) {
    if (isset($element['#default_value'])) {
      if (is_array($element['#default_value'])) {
        foreach ($element['#default_value'] as $k) {
          $items[] = isset($element['#options'][$k]) ? $element['#options'][$k] : $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',
      );
    }
  }
  foreach ($items as $k => $v) {
    $items[$k] = is_string($v) ? check_plain($v) : $v;
  }
  $output = '';
  $output .= theme('item_list', $items, $title, 'ul', array(
    'id' => 'display-' . $type,
  ));
  return $output;
}