58 lines
1.3 KiB
Plaintext
58 lines
1.3 KiB
Plaintext
<?php
|
|
// $Id$
|
|
|
|
/**
|
|
* @file
|
|
* Helper module for AJAX framework tests.
|
|
*/
|
|
|
|
/**
|
|
* Implements hook_menu().
|
|
*/
|
|
function ajax_test_menu() {
|
|
$items['ajax-test/render'] = array(
|
|
'title' => 'ajax_render',
|
|
'page callback' => 'ajax_test_render',
|
|
'delivery callback' => 'ajax_deliver',
|
|
'access callback' => TRUE,
|
|
'type' => MENU_CALLBACK,
|
|
);
|
|
$items['ajax-test/render-error'] = array(
|
|
'title' => 'ajax_render_error',
|
|
'page callback' => 'ajax_test_error',
|
|
'delivery callback' => 'ajax_deliver',
|
|
'access callback' => TRUE,
|
|
'type' => MENU_CALLBACK,
|
|
);
|
|
return $items;
|
|
}
|
|
|
|
/**
|
|
* Menu callback; Returns $_GET['commands'] suitable for use by ajax_deliver().
|
|
*
|
|
* Additionally ensures that ajax_render() incorporates JavaScript settings
|
|
* by invoking drupal_add_js() with a dummy setting.
|
|
*/
|
|
function ajax_test_render() {
|
|
// Prepare AJAX commands.
|
|
$commands = array();
|
|
if (!empty($_GET['commands'])) {
|
|
$commands = $_GET['commands'];
|
|
}
|
|
// Add a dummy JS setting.
|
|
drupal_add_js(array('ajax' => 'test'), 'setting');
|
|
|
|
return array('#type' => 'ajax', '#commands' => $commands);
|
|
}
|
|
|
|
/**
|
|
* Menu callback; Returns AJAX element with #error property set.
|
|
*/
|
|
function ajax_test_error() {
|
|
$message = '';
|
|
if (!empty($_GET['message'])) {
|
|
$message = $_GET['message'];
|
|
}
|
|
return array('#type' => 'ajax', '#error' => $message);
|
|
}
|