theme_test.module

File

drupal/core/modules/system/tests/modules/theme_test/theme_test.module
View source
<?php

/**
 * Implements hook_theme().
 */
function theme_test_theme($existing, $type, $theme, $path) {
  $items['theme_test'] = array(
    'file' => 'theme_test.inc',
    'variables' => array(
      'foo' => '',
    ),
  );
  $items['theme_test_template_test'] = array(
    'template' => 'theme_test.template_test',
  );
  $items['theme_test_template_test_2'] = array(
    'template' => 'theme_test.template_test',
  );
  $items['theme_test_foo'] = array(
    'variables' => array(
      'foo' => NULL,
    ),
  );
  return $items;
}

/**
 * Implements hook_system_theme_info().
 */
function theme_test_system_theme_info() {
  $themes['test_theme'] = drupal_get_path('module', 'system') . '/tests/themes/test_theme/test_theme.info';
  $themes['test_basetheme'] = drupal_get_path('module', 'system') . '/tests/themes/test_basetheme/test_basetheme.info';
  $themes['test_subtheme'] = drupal_get_path('module', 'system') . '/tests/themes/test_subtheme/test_subtheme.info';
  $themes['test_theme_twig'] = drupal_get_path('module', 'system') . '/tests/themes/test_theme_twig/test_theme_twig.info';
  return $themes;
}

/**
 * Implements hook_menu().
 */
function theme_test_menu() {
  $items['theme-test/suggestion'] = array(
    'title' => 'Suggestion',
    'page callback' => '_theme_test_suggestion',
    'access callback' => TRUE,
    'theme callback' => '_theme_custom_theme',
    'type' => MENU_CALLBACK,
  );
  $items['theme-test/alter'] = array(
    'title' => 'Suggestion',
    'page callback' => '_theme_test_alter',
    'access callback' => TRUE,
    '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,
  );
  $items['theme-test/template-test'] = array(
    'page callback' => 'theme_test_template_test_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()',
    ));
  }
  if (arg(0) == 'user' && arg(1) == 'autocomplete') {

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

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

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

/**
 * Menu callback for testing template overridding based on filename.
 */
function theme_test_template_test_page_callback() {
  return theme('theme_test_template_test');
}

/**
 * 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(
    'theme_test__suggestion',
    'theme_test',
  ), array());
}

/**
 * Implements hook_preprocess_HOOK() for html.tpl.php.
 */
function theme_test_preprocess_html(&$variables) {
  $variables['html_attributes']['theme_test_html_attribute'] = 'theme test html attribute value';
  $variables['attributes']['theme_test_body_attribute'] = 'theme test body attribute value';
}

/**
 * Theme function for testing theme('theme_test_foo').
 */
function theme_theme_test_foo($variables) {
  return $variables['foo'];
}

Functions

Namesort descending Description
theme_test_hook_init_page_callback Menu callback for testing themed output generated in hook_init().
theme_test_init Implements hook_init().
theme_test_menu Implements hook_menu().
theme_test_preprocess_html Implements hook_preprocess_HOOK() for html.tpl.php.
theme_test_system_theme_info Implements hook_system_theme_info().
theme_test_template_test_page_callback Menu callback for testing template overridding based on filename.
theme_test_theme Implements hook_theme().
theme_theme_test_foo Theme function for testing theme('theme_test_foo').
_theme_custom_theme Custom theme callback.
_theme_test_alter Page callback, calls drupal_alter().
_theme_test_load_registry Fake registry loading callback.
_theme_test_suggestion Page callback, calls a theme hook suggestion.