You are here

function theme_hierarchical_select_render_dropbox in Hierarchical Select 5.2

Render the dropbox.

Parameters

$hsid: A hierarchical select id.

$dropbox: A dropbox object.

Return value

The rendered HTML.

2 theme calls to theme_hierarchical_select_render_dropbox()
hierarchical_select_json in ./hierarchical_select.module
Menu callback; JSON callback: generates and outputs the appropriate HTML.
theme_hierarchical_select_render_initial_html in ./hierarchical_select.module
Render the initial hierarchical select.

File

./hierarchical_select.module, line 846
This module defines the "hierarchical_select" form element, which is a greatly enhanced way for letting the user select an option in a hierarchy.

Code

function theme_hierarchical_select_render_dropbox($hsid, $dropbox) {
  $output = '';
  $separator = '›';
  $separator_html = '<span class="dropbox-item-separator">' . $separator . '</span>';
  $output .= '<tbody>';
  if (!empty($dropbox->lineages)) {
    foreach ($dropbox->lineages as $id => $lineage) {

      // Preparation: get the labels of the lineage.
      $lineage_labels = array();
      for ($level = 0; $level < count($lineage); $level++) {
        $lineage_labels[] = $lineage[$level]['label'];
      }
      $zebra = ($id + 1) % 2 == 0 ? 'even' : 'odd';
      $first = $id == 0 ? 'first' : '';
      $last = $id == count($dropbox->lineages) - 1 ? 'last' : '';
      $output .= '<tr class="dropbox-entry ' . $first . ' ' . $last . ' ' . $zebra . '">';

      // If the "save lineage" option is enabled: select every item. Otherwise
      // only select the last item.
      $output .= '<td>';
      if ($dropbox->save_lineage) {
        $output .= '<span class="dropbox-selected-item">' . implode('</span>' . $separator_html . '<span class="dropbox-selected-item">', $lineage_labels) . '</span>';
      }
      else {
        $output .= '<span class="dropbox-item">' . implode('</span>' . $separator_html . '<span class="dropbox-item">', array_slice($lineage_labels, 0, count($lineage_labels) - 1)) . '</span>';
        if (count($lineage_labels) > 1) {
          $output .= $separator_html;
        }
        $output .= '<span class="dropbox-selected-item">' . $lineage_labels[count($lineage_labels) - 1] . '</span>';
      }
      $output .= '</td>';

      // Add a column with a "Remove" link.
      $output .= '<td><a id="hierarchical-select-' . $hsid . '-remove-' . $id . '-from-dropbox" class="hierarchical-select-remove-from-dropbox hierarchical-select-' . $hsid . '-remove-from-dropbox">' . t('Remove') . '</a></td>';
      $output .= '</tr>';
    }
  }
  else {
    $output .= '<tr class="dropbox-entry first last dropbox-is-empty"><td>' . t('Nothing has been selected yet.') . '</td></tr>';
  }

  // Add the dropbox title as a table caption.
  $output .= '<caption class="dropbox-title">' . check_plain($dropbox->title) . '</caption>';
  $output .= '</tbody>';
  return $output;
}