function hierarchical_select_get_dropbox in Hierarchical Select 5.2
Generate the dropbox object.
Parameters
$module: The module that should be used for HS hooks.
$selection: The selection based on which a dropbox should be generated.
$save_lineage: Whether the "save lineage" option is enabled or not.
$level_labels: An array of labels, one per level. Optional.
$params: An array of parameters, which may be necessary for some implementations. Optional.
$title: A title that should be displayed above the dropbox. Optional.
Return value
A dropbox object.
3 calls to hierarchical_select_get_dropbox()
- hierarchical_select_json in ./
hierarchical_select.module - Menu callback; JSON callback: generates and outputs the appropriate HTML.
- hierarchical_select_process in ./
hierarchical_select.module - Hierarchical select form element processing function.
- _hierarchical_select_validate in ./
hierarchical_select.module - Hierarchical select form element validate callback.
File
- ./
hierarchical_select.module, line 488 - 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 hierarchical_select_get_dropbox($module, $selection, $save_lineage, $level_labels = array(), $params = array(), $title = '') {
$dropbox = new stdClass();
$dropbox->title = !empty($title) ? $title : t('All selections');
$dropbox->lineages = array();
$dropbox->lineages_selections = array();
// Clean selection.
if (is_array($selection)) {
foreach ($selection as $key => $item) {
if (!module_invoke($module, 'hierarchical_select_valid_item', $item, $params)) {
unset($selection[$key]);
}
}
}
else {
if (!module_invoke($module, 'hierarchical_select_valid_item', $selection, $params)) {
$selection = array();
}
}
if (!empty($selection)) {
// Remove all duplicate values from the selection. We'll work with this
// *set* (repeating values don't matter) of selected items in the code.
$selection = is_array($selection) ? array_unique($selection) : array(
$selection,
);
// Store the "save lineage" setting, needed in the theming layer.
$dropbox->save_lineage = $save_lineage;
if ($save_lineage) {
$dropbox->lineages = _hierarchical_select_reconstruct_lineages_save_lineage_enabled($module, $selection, $params);
}
else {
// Retrieve the lineage of each item. Ignore invalid items.
foreach ($selection as $item) {
if (module_invoke($module, 'hierarchical_select_valid_item', $item, $params)) {
$dropbox->lineages[] = module_invoke($module, 'hierarchical_select_lineage', $item, $params);
}
}
foreach ($dropbox->lineages as $id => $lineage) {
foreach ($lineage as $level => $item) {
$dropbox->lineages[$id][$level] = array(
'value' => $item,
'label' => module_invoke($module, 'hierarchical_select_item_get_label', $item, $params),
);
}
}
}
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'];
}
}
}
return $dropbox;
}