function ctools_ajax_render in Chaos Tool Suite (ctools) 6
Render a commands array into JSON and immediately hand this back to the AJAX requester.
17 calls to ctools_ajax_render()
- ctools_access_ajax_add in includes/
context-access-admin.inc - AJAX callback to add a new access test to the list.
- ctools_access_ajax_delete in includes/
context-access-admin.inc - AJAX command to remove an access control item.
- ctools_access_ajax_edit in includes/
context-access-admin.inc - AJAX callback to edit an access test in the list.
- ctools_ajax_render_error in includes/
ajax.inc - Send an error response back via AJAX and immediately exit.
- ctools_ajax_sample_animal in ctools_ajax_sample/
ctools_ajax_sample.module - A modal login callback.
File
- includes/
ajax.inc, line 459 - Utilize the CTools AJAX responder.
Code
function ctools_ajax_render($commands = array()) {
// Although ajax_deliver() does this, some contributed and custom modules
// render AJAX responses without using that delivery callback.
ctools_ajax_set_verification_header();
$js_files = array();
$settings = ctools_process_js_files($js_files, 'header');
$settings += ctools_process_js_files($js_files, 'footer');
$query_string = '?' . substr(variable_get('css_js_query_string', '0'), 0, 1);
$css = drupal_add_css();
foreach ($css as $media => $types) {
// If CSS preprocessing is off, we still need to output the styles.
// Additionally, go through any remaining styles if CSS preprocessing is on and output the non-cached ones.
foreach ($types as $type => $files) {
if ($type == 'module') {
// Setup theme overrides for module styles.
$theme_styles = array();
foreach (array_keys($css[$media]['theme']) as $theme_style) {
$theme_styles[] = basename($theme_style);
}
}
// The theme stuff should already be added and because of admin themes,
// this could cause different CSS to be added.
if ($type != 'theme') {
foreach ($types[$type] as $file => $preprocess) {
// If the theme supplies its own style using the name of the module style, skip its inclusion.
// This includes any RTL styles associated with its main LTR counterpart.
if ($type == 'module' && in_array(str_replace('-rtl.css', '.css', basename($file)), $theme_styles)) {
// Unset the file to prevent its inclusion when CSS aggregation is enabled.
unset($types[$type][$file]);
continue;
}
// Only include the stylesheet if it exists.
if (file_exists($file)) {
$css_files[] = array(
'file' => base_path() . $file . $query_string,
'media' => $media,
);
}
}
}
}
}
if (!empty($js_files)) {
array_unshift($commands, ctools_ajax_command_scripts(array_keys($js_files)));
}
if (!empty($css_files)) {
array_unshift($commands, ctools_ajax_command_css_files($css_files));
}
if (!empty($settings)) {
array_unshift($commands, ctools_ajax_command_settings(call_user_func_array('array_merge_recursive', $settings)));
}
if (!empty($_REQUEST['ctools_multipart'])) {
// We don't use drupal_json here because the header is not true. We're not really
// returning JSON, strictly-speaking, but rather JSON content wrapped in a <textarea>
// as per the "file uploads" example here: http://malsup.com/jquery/form/#code-samples
echo '<textarea>' . drupal_to_js($commands) . '</textarea>';
}
else {
drupal_json($commands);
}
exit;
}