function fieldset_helper_state_manager_get_lookup_id in Fieldset helper 6
Same name and namespace in other branches
- 6.2 fieldset_helper.module \fieldset_helper_state_manager_get_lookup_id()
- 7.2 fieldset_helper.module \fieldset_helper_state_manager_get_lookup_id()
Get the lookup id for the $element_id in the current path.
Parameters
$element_id: The DOM element id.
Return value
The numeric auto generated look up id for the $element_id. If $element_id is not set then the entire lookup id table for the current page will returned.
2 calls to fieldset_helper_state_manager_get_lookup_id()
- FieldsetHelperTestCase::setFieldsetHelperStateManagerCookie in ./
fieldset_helper.test - Resets the Fieldset helper state manager cookies value for every loaded fieldset.
- fieldset_helper_state_manager_get_state in ./
fieldset_helper.module - Get fieldset's collapsed state.
File
- ./
fieldset_helper.module, line 340 - Saves the collapsed state of a Drupal collapsible fieldset.
Code
function fieldset_helper_state_manager_get_lookup_id($element_id = NULL) {
static $lookup_id_table;
$current_path = $_GET['q'];
// Load existing lookup ids for the current path from the database.
if (!isset($lookup_id_table)) {
// Fetch lookup records for the current path
$query = "SELECT id, element_id FROM {fieldset_helper_state_manager} WHERE path='%s'";
$result = db_query($query, $current_path);
while ($data = db_fetch_array($result)) {
$lookup_id_table[$data['element_id']] = $data['id'];
}
// Initialize state manager js ids
$settings['fieldset_helper_state_manager']['ids'] = $lookup_id_table;
$settings['fieldset_helper_cookie_duration'] = variable_get('fieldset_helper_cookie_duration', 0);
drupal_add_js($settings, 'setting');
}
// Create a new lookup id for element_id's not associated with the current path in the lookup id table.
if ($element_id != NULL && !isset($lookup_id_table[$element_id])) {
// Get id for path and element_id combination.
$sql = "INSERT INTO {fieldset_helper_state_manager} (path, element_id) VALUES ('%s', '%s')";
db_query($sql, $current_path, $element_id);
$lookup_id = db_last_insert_id('fieldset_helper_state_manager', 'id');
$lookup_id_table[$element_id] = $lookup_id;
// Add lookup id to state manager js ids
$settings['fieldset_helper_state_manager']['ids'][$element_id] = $lookup_id;
drupal_add_js($settings, 'setting');
}
// Return the look up id for the element id.
return $element_id == NULL ? $lookup_id_table : $lookup_id_table[$element_id];
}