Index: hierarchical_select.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/hierarchical_select/hierarchical_select.module,v retrieving revision 1.12 diff -u -r1.12 hierarchical_select.module --- hierarchical_select.module 29 Dec 2007 14:11:24 -0000 1.12 +++ hierarchical_select.module 29 Dec 2007 15:11:32 -0000 @@ -330,32 +330,34 @@ $separator = '›'; $separator_html = ''. $separator .''; - 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']; - } - - $output .= '
'; - - // If the "save lineage" option is enabled: select every item. Otherwise - // only select the last item. - if ($dropbox->save_lineage) { - $output .= ''. implode(''. $separator_html .'', $lineage_labels) .''; - } - else { - $output .= ''. implode(''. $separator_html .'', array_slice($lineage_labels, 0, count($lineage_labels) - 1)) .''; - if (count($lineage_labels) > 1) { - $output .= $separator_html; + if ($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']; } - $output .= ''. $lineage_labels[count($lineage_labels) - 1] .''; + + $output .= '
'; + + // If the "save lineage" option is enabled: select every item. Otherwise + // only select the last item. + if ($dropbox->save_lineage) { + $output .= ''. implode(''. $separator_html .'', $lineage_labels) .''; + } + else { + $output .= ''. implode(''. $separator_html .'', array_slice($lineage_labels, 0, count($lineage_labels) - 1)) .''; + if (count($lineage_labels) > 1) { + $output .= $separator_html; + } + $output .= ''. $lineage_labels[count($lineage_labels) - 1] .''; + } + + // Add a "Remove" link. + $output .= ''. t('Remove') .''; + + $output .= '
'; } - - // Add a "Remove" link. - $output .= ''. t('Remove') .''; - - $output .= '
'; } return $output; @@ -529,19 +531,21 @@ } } - usort($dropbox->lineages, '_hierarchical_select_dropbox_sort'); - - // Now store each lineage's selection too. This is needed on the client side - // to enable the remove button to let the server know which selected items - // should be removed. - foreach ($dropbox->lineages as $id => $lineage) { - if ($save_lineage) { - // Store the entire lineage. - $dropbox->lineages_selections[$id] = array_map('_hierarchical_select_dropbox_lineage_item_get_value', $lineage); - } - else { - // Store only the last (aka the deepest) value of the lineage. - $dropbox->lineages_selections[$id][0] = $lineage[count($lineage) - 1]['value']; + if ($dropbox->lineages) { + usort($dropbox->lineages, '_hierarchical_select_dropbox_sort'); + + // Now store each lineage's selection too. This is needed on the client side + // to enable the remove button to let the server know which selected items + // should be removed. + foreach ($dropbox->lineages as $id => $lineage) { + if ($save_lineage) { + // Store the entire lineage. + $dropbox->lineages_selections[$id] = array_map('_hierarchical_select_dropbox_lineage_item_get_value', $lineage); + } + else { + // Store only the last (aka the deepest) value of the lineage. + $dropbox->lineages_selections[$id][0] = $lineage[count($lineage) - 1]['value']; + } } }