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

Drupal example source code file (theme_test.module)

This example Drupal source code file (theme_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

_theme_custom_theme, access, arg, args, array, callback, data, function, page, php, return, theme, title, type

The theme_test.module Drupal example source code

<?php
// $Id: theme_test.module,v 1.4 2010/08/22 12:46:21 dries Exp $

/**
 * Implements hook_menu().
 */
function theme_test_menu() {
  $items['theme-test/suggestion'] = array(
    'title' => 'Suggestion',
    'page callback' => '_theme_test_suggestion',
    'access arguments' => array('access content'),
    'theme callback' => '_theme_custom_theme',
    'type' => MENU_CALLBACK,
  );
  $items['theme-test/alter'] = array(
    'title' => 'Suggestion',
    'page callback' => '_theme_test_alter',
    'access arguments' => array('access content'),
    'theme callback' => '_theme_custom_theme',
    'type' => MENU_CALLBACK,
  );
  $items['theme-test/hook-init'] = array(
    'page callback' => 'theme_test_hook_init_page_callback',
    'access callback' => TRUE,
    'type' => MENU_CALLBACK,
  );
  return $items;
}

/**
 * Implements hook_init().
 */
function theme_test_init() {
  if (arg(0) == 'theme-test' && arg(1) == 'hook-init') {
    // First, force the theme registry to be rebuilt on this page request. This
    // allows us to test a full initialization of the theme system in the code
    // below.
    drupal_theme_rebuild();
    // Next, initialize the theme system by storing themed text in a global
    // variable. We will use this later in theme_test_hook_init_page_callback()
    // to test that even when the theme system is initialized this early, it is
    // still capable of returning output and theming the page as a whole.
    $GLOBALS['theme_test_output'] = theme('more_link', array('url' => 'user', 'title' => 'Themed output generated in hook_init()'));
  }
}

/**
 * Implements hook_exit().
 */
function theme_test_exit() {
  if (arg(0) == 'user') {
    // Register a fake registry loading callback. If it gets called by
    // theme_get_registry(), the registry has not been initialized yet.
    _theme_registry_callback('_theme_test_load_registry', array());
    print theme_get_registry() ? 'registry initialized' : 'registry not initialized';
  }
}

/**
 * Fake registry loading callback.
 */
function _theme_test_load_registry() {
  return array();
}

/**
 * Menu callback for testing themed output generated in hook_init().
 */
function theme_test_hook_init_page_callback() {
  return $GLOBALS['theme_test_output'];
}

/**
 * Custom theme callback.
 */
function _theme_custom_theme() {
  return 'test_theme';
}

/**
 * Page callback, calls drupal_alter().
 *
 * This is for testing that the theme can have hook_*_alter() implementations
 * that run during page callback execution, even before theme() is called for
 * the first time.
 */
function _theme_test_alter() {
  $data = 'foo';
  drupal_alter('theme_test_alter', $data);
  return "The altered data is $data.";
}

/**
 * Page callback, calls a theme hook suggestion.
 */
function _theme_test_suggestion() {
  return theme(array('breadcrumb__suggestion', 'breadcrumb'), array());
}

/**
 * Implements hook_preprocess_breadcrumb().
 *
 * Set a variable that can later be tested to see if this function ran.
 */
function theme_test_preprocess_breadcrumb(&$variables) {
  $variables['theme_test_preprocess_breadcrumb'] = 1;
}

Other Drupal examples (source code examples)

Here is a short list of links related to this Drupal theme_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.