function hierarchical_select_json in Hierarchical Select 5.2
Same name and namespace in other branches
- 5.3 hierarchical_select.module \hierarchical_select_json()
- 6.3 hierarchical_select.module \hierarchical_select_json()
Menu callback; JSON callback: generates and outputs the appropriate HTML.
2 string references to 'hierarchical_select_json'
- hierarchical_select_menu in ./
hierarchical_select.module - Implementation of hook_menu().
- hierarchical_select_process in ./
hierarchical_select.module - Hierarchical select form element processing function.
File
- ./
hierarchical_select.module, line 85 - 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_json() {
// We are returning JavaScript, so tell the browser. Ripped from Drupal 6's
// drupal_json() function.
drupal_set_header('Content-Type: text/javascript; charset=utf-8');
// Extract the common parameters.
$hsid = $_POST['hsid'];
$module = $_POST['module'];
$selection = !strstr($_POST['selection'], '|') ? $_POST['selection'] : explode('|', $_POST['selection']);
$dropbox_selection = !strstr($_POST['dropbox_selection'], '|') ? $_POST['dropbox_selection'] : explode('|', $_POST['dropbox_selection']);
$save_lineage = _hierarchical_select_str_to_bool($_POST['save_lineage']);
$enforce_deepest = _hierarchical_select_str_to_bool($_POST['enforce_deepest']);
$all_option = _hierarchical_select_str_to_bool($_POST['all_option']);
$level_labels = explode('|', $_POST['level_labels']);
$params = unserialize($_POST['params']);
$dropbox_title = $_POST['dropbox_title'];
$required = _hierarchical_select_str_to_bool($_POST['required']);
switch ($_POST['type']) {
case 'hierarchical-select':
$hierarchy = hierarchical_select_get_hierarchy($module, $selection, $save_lineage, $enforce_deepest, $all_option, $level_labels, $params, $required, FALSE);
$hierarchical_select_html = theme('hierarchical_select_render_selects', $hsid, $hierarchy);
// Return output as JSON.
print drupal_to_js(array(
'hierarchicalSelect' => $hierarchical_select_html,
));
break;
case 'dropbox-add':
// We want to render an empty select.
$selection = -1;
case 'dropbox-remove':
default:
$dropbox = hierarchical_select_get_dropbox($module, $dropbox_selection, $save_lineage, $level_labels, $params, $dropbox_title);
$dropbox_html = theme('hierarchical_select_render_dropbox', $hsid, $dropbox);
$hierarchy = hierarchical_select_get_hierarchy($module, $selection, $save_lineage, $enforce_deepest, $all_option, $level_labels, $params, $required, $dropbox);
$hierarchical_select_html = theme('hierarchical_select_render_selects', $hsid, $hierarchy);
// Return output as JSON.
print drupal_to_js(array(
'hierarchicalSelect' => $hierarchical_select_html,
'dropbox' => $dropbox_html,
'dropboxLineagesSelections' => $dropbox->lineages_selections,
));
break;
}
exit;
}