function matrix_settings_throbber_save in Matrix field 6.2
AJAX callback for saving an individual element Takes parameters from $_REQUEST Saves the data into the Drupal cache Echos JSON data which contains: serialized data (which is what will be eventually saved into the database) list of elements for row/column
1 string reference to 'matrix_settings_throbber_save'
- matrix_menu in ./
matrix.module - Implementation of hook_menu().
File
- ./
admin.inc, line 60 - Provides functions used in the creation of matrix fields.
Code
function matrix_settings_throbber_save() {
$field_name = $_REQUEST['field_name'];
$element_id = $_REQUEST['element_id'];
$rc = $_REQUEST['rc'];
$mode = $_REQUEST['mode'];
$cache_response = cache_get('matrix-' . $rc . '-' . $field_name);
//load existing elements from cache
$elements = (array) $cache_response->data;
//build the new element
$data['#type'] = $_REQUEST['element_type'];
$data['#title'] = $_REQUEST['title'];
$data['#options'] = $_REQUEST['options'];
$data['#validation'] = $_REQUEST['validation'];
$data['#size'] = $_REQUEST['size'] != 'undefined' ? $_REQUEST['size'] : '';
$data['#required'] = $_REQUEST['required'] == 'true' ? 1 : 0;
$data['#calc_method'] = $_REQUEST['calc_method'];
$data['#php'] = $_REQUEST['php'] == 'true' ? 1 : 0;
if ($element_id !== '') {
$elements[$element_id] = $data;
}
else {
$elements[] = $data;
}
$elements = array_values($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;
}