function hierarchical_select_after_build in Hierarchical Select 5.3
Same name and namespace in other branches
- 6.3 hierarchical_select.module \hierarchical_select_after_build()
Hierarchical select form element type #after_build callback.
1 string reference to 'hierarchical_select_after_build'
- hierarchical_select_form_alter in ./
hierarchical_select.module - Implementation of hook_form_alter().
File
- ./
hierarchical_select.module, line 642 - 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_after_build($form, $form_values) {
$names = _hierarchical_select_store_name(NULL, NULL, TRUE);
$post_hs_form_build_id = _hierarchical_select_get_hs_form_build_id();
if (!isset($post_hs_form_build_id) && count($names)) {
$parameters = isset($form['#parameters']) ? $form['#parameters'] : array();
// Collect information in this array, which will be used in dynamic form
// updates, to …
$storage = array(
// … retrieve $form.
'parameters' => $parameters,
// … determine which part of $form should be rendered.
'#names' => $names,
);
if (module_exists('i18n')) {
$storage['i18n'] = array(
'mode' => i18n_selection_mode(),
'params' => i18n_selection_mode('params'),
);
}
// 6 hours cache life time for forms should be plenty.
$expire = 21600;
// Store the information needed for dynamic form updates in the cache, so
// we can retrieve this in our JSON callbacks (to be able to rebuild and
// render part of the form).
$hs_form_build_id = 'hs_form_' . md5(mt_rand());
cache_set($hs_form_build_id, 'cache', serialize($storage), time() + $expire);
}
elseif (isset($post_hs_form_build_id)) {
// Don't generate a new hs_form_build_id if this is a re-rendering of the
// same form!
$hs_form_build_id = $post_hs_form_build_id;
}
// Store the hs_form_build_id in a hidden value, so that it gets POSTed.
$form_element = array(
'#type' => 'hidden',
'#value' => $hs_form_build_id,
// We have to set #parents manually because we want to send only
// $form_element through form_builder(), not $form. If we set #parents,
// form_builder() has all info it needs to generate #name and #id.
'#parents' => array(
'hs_form_build_id',
),
);
$form['hs_form_build_id'] = form_builder($form['form_id']['#value'], $form_element);
// Pass the hs_form_build_id to a custom submit function that will clear
// the associated values from the cache.
$form['#submit']['_hierarchical_select_submit'] = array(
$post_hs_form_build_id,
);
return $form;
}