function matrix_settings_reorder_save in Matrix field 6.2
@file Provides functions used in the creation of matrix fields.
1 string reference to 'matrix_settings_reorder_save'
- matrix_menu in ./
matrix.module - Implementation of hook_menu().
File
- ./
admin.inc, line 7 - Provides functions used in the creation of matrix fields.
Code
function matrix_settings_reorder_save() {
$field_name = $_REQUEST['field_name'];
$source = (int) $_REQUEST['source'];
$destination = (int) $_REQUEST['destination'];
$rc = $_REQUEST['rc'];
$mode = $_REQUEST['mode'];
$cache_response = cache_get('matrix-' . $rc . '-' . $field_name);
//load existing elements from cache
$elements = (array) $cache_response->data;
$move_element = $elements[$source];
foreach ($elements as $id => $element) {
if ($source < $destination) {
if ($id != $source) {
$fixed_elements[] = $element;
}
if ($id == $destination) {
$fixed_elements[] = $move_element;
}
}
else {
if ($id == $destination) {
$fixed_elements[] = $move_element;
}
if ($id != $source) {
$fixed_elements[] = $element;
}
}
}
$elements = array_values($fixed_elements);
//this rekeys the array so it remains sequential.
cache_set('matrix-' . $rc . '-' . $field_name, $elements);
//save all elements back to the cache
$list .= theme('matrix_settings_list', $elements, $rc);
$rows_elements = cache_get('matrix-rows-' . $field_name);
//load existing elements from cache
$cols_elements = cache_get('matrix-cols-' . $field_name);
//load existing elements from cache
$preview = drupal_get_form('matrix_settings_preview', $field_name, $mode, $rows_elements->data, $cols_elements->data);
echo drupal_to_js(array(
'list' => $list,
'data' => serialize($elements),
'preview' => $preview,
));
exit;
}