You are here

function theme_hs_content_taxonomy_formatter_hierarchical in Hierarchical Select 6.3

Theme function for HS Content Taxonomy formatters.

1 string reference to 'theme_hs_content_taxonomy_formatter_hierarchical'
hs_content_taxonomy_theme in modules/hs_content_taxonomy.module
Implementation of hook_theme().

File

modules/hs_content_taxonomy.module, line 287
Implementation of the Hierarchical Select API for the Content Taxonomy module.

Code

function theme_hs_content_taxonomy_formatter_hierarchical($element) {
  $output = '';

  // Extract required field information.
  // $element contains only field name; so we use cck function to get more info.
  $field = content_fields($element['#field_name'], $element['#type_name']);
  $field_name = $field['field_name'];
  $vid = $field['vid'];
  $tid = empty($field['tid']) ? 0 : $field['tid'];
  $depth = empty($field['depth']) ? 0 : $field['depth'];

  // Get the config for this field.
  require_once drupal_get_path('module', 'hierarchical_select') . '/includes/common.inc';
  $config_id = "content-taxonomy-{$field_name}";
  $config = hierarchical_select_common_config_get($config_id);
  $config += array(
    'module' => 'hs_content_taxonomy',
    'params' => array(
      'vid' => $vid,
      'tid' => $tid,
      'depth' => $depth,
    ),
  );
  $selection = array();

  // Cycle through elements.
  foreach (element_children($element) as $key) {
    if (isset($element[$key]['#item']['value'])) {
      $selection[] = $element[$key]['#item']['value'];
    }
  }

  // It is said that formatter theme function is called even if field is empty.
  if (empty($selection)) {
    return $output;
  }

  // Generate a dropbox out of the selection. This will automatically
  // calculate all lineages for us.
  $dropbox = _hierarchical_select_dropbox_generate($config, $selection);

  // Actual formatting.
  // In 6.x formatter is fully themable
  // We theme each lineage using additional theme function
  $num_items = count($dropbox->lineages);
  $flip = array(
    'even' => 'odd',
    'odd' => 'even',
  );
  $class = 'even';
  $output = '<ul class="hierarchical-select-lineages">';
  foreach ($dropbox->lineages as $i => $lineage) {
    $class = $flip[$class];
    $classes = ' ' . $class;
    if ($i == 0) {
      $classes .= ' first';
    }
    if ($i == $num_items - 1) {
      $classes .= ' last';
    }
    $output .= '<li class="lineage-' . $i . $classes . '">';
    $output .= theme('hs_content_taxonomy_row', $lineage, $element['#formatter']);
    $output .= '</li>';
  }
  $output .= '</ul>';

  // Add the CSS.
  drupal_add_css(drupal_get_path('module', 'hierarchical_select') . '/hierarchical_select.css');
  return $output;
}