home | career | drupal | java | mac | mysql | perl | php | scala | uml | unix

Drupal example source code file (ajax_test.module)

This example Drupal source code file (ajax_test.module) is included in the DevDaily.com "Drupal Source Code Warehouse" project. The intent of this project is to help you "Learn Drupal by Example".

PHP - Drupal tags/keywords

access, ajax, array, callback, file, function, link, message, page, php, return, title, true, type

The ajax_test.module Drupal example source code

<?php
// $Id: ajax_test.module,v 1.5 2010/10/21 19:31:39 dries Exp $

/**
 * @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,
  );
  $items['ajax-test/link'] = array(
    'title' => 'AJAX Link',
    'page callback' => 'ajax_test_link',
    'access callback' => TRUE,
  );
  return $items;
}

/**
 * Menu callback; Return an element suitable for use by ajax_deliver().
 *
 * Additionally ensures that ajax_render() incorporates JavaScript settings
 * generated during the page request by invoking drupal_add_js() with a dummy
 * setting.
 */
function ajax_test_render() {
  drupal_add_js(array('ajax' => 'test'), 'setting');
  return array('#type' => 'ajax', '#commands' => array());
}

/**
 * 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);
}

/**
 * Menu callback; Renders a #type link with #ajax.
 */
function ajax_test_link() {
  $build['link'] = array(
    '#type' => 'link',
    '#title' => 'Show help',
    '#href' => 'filter/tips',
    '#ajax' => array(
      'wrapper' => 'block-system-main',
    ),
  );
  return $build;
}

Other Drupal examples (source code examples)

Here is a short list of links related to this Drupal ajax_test.module source code file:

new blog posts

"Drupal" is a registered trademark of Dries Buytaert.

my drupal tutorials and examples  

Copyright 1998-2016 Alvin Alexander, alvinalexander.com
All Rights Reserved.

Beginning in 2016, a portion of the proceeds from pages under the '/drupal-code-examples/' URI will be donated to charity.