ajax_test.module 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. /**
  3. * @file
  4. * Helper module for Ajax framework tests.
  5. */
  6. /**
  7. * Implements hook_menu().
  8. */
  9. function ajax_test_menu() {
  10. $items['ajax-test/render'] = array(
  11. 'title' => 'ajax_render',
  12. 'page callback' => 'ajax_test_render',
  13. 'delivery callback' => 'ajax_deliver',
  14. 'access callback' => TRUE,
  15. 'type' => MENU_CALLBACK,
  16. );
  17. $items['ajax-test/render-error'] = array(
  18. 'title' => 'ajax_render_error',
  19. 'page callback' => 'ajax_test_error',
  20. 'delivery callback' => 'ajax_deliver',
  21. 'access callback' => TRUE,
  22. 'type' => MENU_CALLBACK,
  23. );
  24. $items['ajax-test/link'] = array(
  25. 'title' => 'AJAX Link',
  26. 'page callback' => 'ajax_test_link',
  27. 'access callback' => TRUE,
  28. );
  29. return $items;
  30. }
  31. /**
  32. * Implements hook_system_theme_info().
  33. */
  34. function ajax_test_system_theme_info() {
  35. $themes['test_theme'] = drupal_get_path('module', 'ajax_test') . '/themes/test_theme/test_theme.info';
  36. return $themes;
  37. }
  38. /**
  39. * Menu callback; Return an element suitable for use by ajax_deliver().
  40. *
  41. * Additionally ensures that ajax_render() incorporates JavaScript settings
  42. * generated during the page request by invoking drupal_add_js() with a dummy
  43. * setting.
  44. */
  45. function ajax_test_render() {
  46. drupal_add_js(array('ajax' => 'test'), 'setting');
  47. return array('#type' => 'ajax', '#commands' => array());
  48. }
  49. /**
  50. * Menu callback; Returns Ajax element with #error property set.
  51. */
  52. function ajax_test_error() {
  53. $message = '';
  54. if (!empty($_GET['message'])) {
  55. $message = $_GET['message'];
  56. }
  57. return array('#type' => 'ajax', '#error' => $message);
  58. }
  59. /**
  60. * Menu callback; Renders a #type link with #ajax.
  61. */
  62. function ajax_test_link() {
  63. $build['link'] = array(
  64. '#type' => 'link',
  65. '#title' => 'Show help',
  66. '#href' => 'filter/tips',
  67. '#ajax' => array(
  68. 'wrapper' => 'block-system-main',
  69. ),
  70. );
  71. return $build;
  72. }