function form_builder_cache_difference in Form Builder 6
Same name and namespace in other branches
- 7.2 includes/form_builder.cache.inc \form_builder_cache_difference()
- 7 includes/form_builder.cache.inc \form_builder_cache_difference()
Compare the cached form with the original and return all changed elements.
Return value
An array of elements keyed by the element_id of the changed element. Each value contains an array of the 'original' and 'modified' elements.
File
- includes/
form_builder.cache.inc, line 83 - form_builder.cache.inc Functions for temporary storage of form builder structures while editing.
Code
function form_builder_cache_difference($form_type, $form_id, $exclude_weight = TRUE) {
if (($modified_form = form_builder_cache_load($form_type, $form_id)) && $modified_form !== FALSE) {
$original_form = form_builder_load_form($form_type, $form_id);
$original_ids = form_builder_get_element_ids($original_form);
$modified_ids = form_builder_get_element_ids($modified_form);
// Find the union of IDs in both arrays.
$element_ids = array_keys(array_flip($original_ids) + array_flip($modified_ids));
// Build a list of all elements that have changed.
$differences = array();
foreach ($element_ids as $element_id) {
$original = form_builder_get_element($original_form, $element_id);
$modified = form_builder_get_element($modified_form, $element_id);
if ($exclude_weight) {
if (isset($original['#weight'])) {
unset($original['#weight']);
}
if (isset($modified['#weight'])) {
unset($modified['#weight']);
}
}
if ($original != $modified) {
$differences[$element_id] = array(
'original' => $original,
'modified' => $modified,
);
}
}
return $differences;
}
return FALSE;
}