function ds_ajax_add_field in Display Suite 7
Same name and namespace in other branches
- 7.2 modules/ds_ui/includes/ds.fields.inc \ds_ajax_add_field()
Handles ctools modal Add field
Parameters
$js: Whether js is used or not.
$field_type: The name of the field type.
File
- ./
ds.field_ui.inc, line 1147 - Field UI functions for Display Suite.
Code
function ds_ajax_add_field($js, $field_type) {
if (!$js) {
// We don't support degrading this from js because we're not
// using the server to remember the state of the table.
drupal_goto("admin/structure/ds/fields/" . $field_type);
return;
}
ctools_include('ajax');
ctools_include('modal');
switch ($field_type) {
case "manage_ctools":
$title = t('Add a dynamic field');
$form_name = "ds_edit_ctools_field_form";
break;
case "manage_preprocess":
$title = t('Add a preprocess field');
$form_name = "ds_edit_preprocess_field_form";
break;
case "manage_block":
$title = t('Add a block field');
$form_name = "ds_edit_block_field_form";
break;
default:
$title = t('Add a code field');
$form_name = "ds_edit_custom_field_form";
$field_type = 'manage_custom';
break;
}
$form_state = array();
$form_state['build_info']['args'] = array();
$form_state += array(
'title' => $title,
'ajax' => TRUE,
're_render' => FALSE,
);
$output = NULL;
form_load_include($form_state, 'inc', 'ds', 'ds.fields');
$output = ctools_modal_form_wrapper($form_name, $form_state);
// Field is saved.
if ($form_state['executed']) {
$output = array();
// Do not print messages on screen.
if ($messages = theme('status_messages')) {
$output[] = ajax_command_append('#console', $messages);
}
// Close the modal.
$output[] = ctools_modal_command_dismiss();
// Call our own javascript function which will trigger a refresh of the table.
$output[] = ajax_command_invoke('#field-display-overview', 'dsRefreshDisplayTable');
}
drupal_add_http_header('Content-Type', 'application/json');
print ajax_render($output);
exit;
}