function _hierarchial_select_enforce_deepest_selection in Hierarchical Select 5.2
Same name and namespace in other branches
- 5 hierarchical_select.module \_hierarchial_select_enforce_deepest_selection()
Helper function to update the lineage of the hierarchy to ensure that the user selects an item in the deepest level of the hierarchy.
Parameters
$lineage: The lineage up to the deepest selection the user has made so far.
$root_level: The options in the root level.
$module: The module that should be used for HS hooks.
$params: The params that should be passed to HS hooks.
Return value
The updated lineage.
1 call to _hierarchial_select_enforce_deepest_selection()
- hierarchical_select_get_hierarchy in ./
hierarchical_select.module - Generate the hierarchy object.
File
- ./
hierarchical_select.module, line 668 - 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 _hierarchial_select_enforce_deepest_selection($lineage, $root_level, $module, $params) {
// Use the deepest item as the first parent. Then apply this algorithm:
// 1) get the parent's children, stop if no children
// 2) choose the first child as the option that is selected by default, by
// adding it to the lineage of the hierarchy
// 3) make this child the parent, go to step 1.
$parent = end($lineage);
// The last item in the lineage is the deepest one.
$children = module_invoke($module, 'hierarchical_select_children', $parent, $params);
while (count($children)) {
$first_child = reset(array_keys($children));
$lineage[] = $first_child;
$parent = $first_child;
$children = module_invoke($module, 'hierarchical_select_children', $parent, $params);
}
return $lineage;
}