function _hierarchical_select_dropbox_generate in Hierarchical Select 5.3
Same name and namespace in other branches
- 6.3 hierarchical_select.module \_hierarchical_select_dropbox_generate()
- 7.3 hierarchical_select.module \_hierarchical_select_dropbox_generate()
Generate the dropbox object.
Parameters
$config: A config array with at least the following settings:
- module
- save_lineage
- params
- dropbox
- title
$selection: The selection based on which a dropbox should be generated.
Return value
A dropbox object.
4 calls to _hierarchical_select_dropbox_generate()
- hierarchical_select_process in ./
hierarchical_select.module - Hierarchical select form element type #process callback.
- hs_content_taxonomy_field_formatter in modules/
hs_content_taxonomy.module - Implemenation of hook_field_formatter().
- theme_hierarchical_select_selection_as_lineages in ./
hierarchical_select.module - Themeing function to render a selection (of items) according to a given Hierarchical Select configuration as one or more lineages.
- _hs_taxonomy_token_termpath_for_vid in modules/
hs_taxonomy.module - Helper function for hs_taxonomy_token_values().
File
- ./
hierarchical_select.module, line 1969 - This module defines the "hierarchical_select" form element, which is a greatly enhanced way for letting the user select items in a hierarchy.
Code
function _hierarchical_select_dropbox_generate($config, $selection) {
$dropbox = new stdClass();
$start = microtime();
$dropbox->title = !empty($config['dropbox']['title']) ? $config['dropbox']['title'] : t('All selections');
$dropbox->lineages = array();
$dropbox->lineages_selections = array();
// Clean selection.
foreach ($selection as $key => $item) {
if (!module_invoke($config['module'], 'hierarchical_select_valid_item', $item, $config['params'])) {
unset($selection[$key]);
}
}
if (!empty($selection)) {
// Store the "save lineage" setting, needed in the rendering layer.
$dropbox->save_lineage = $config['save_lineage'];
if ($config['save_lineage']) {
$dropbox->lineages = _hierarchical_select_dropbox_reconstruct_lineages_save_lineage_enabled($config['module'], $selection, $config['params']);
}
else {
// Retrieve the lineage of each item.
foreach ($selection as $item) {
$dropbox->lineages[] = module_invoke($config['module'], 'hierarchical_select_lineage', $item, $config['params']);
}
// We will also need the labels of each item in the rendering layer.
foreach ($dropbox->lineages as $id => $lineage) {
foreach ($lineage as $level => $item) {
$dropbox->lineages[$id][$level] = array(
'value' => $item,
'label' => check_plain(module_invoke($config['module'], 'hierarchical_select_item_get_label', $item, $config['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 ($config['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'];
}
}
}
// Calculate the time it took to build the dropbox object.
$dropbox->build_time = (microtime() - $start) * 1000;
return $dropbox;
}