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,
    ),
  );
  $items['theme_test_render_element'] = array(
    'render element' => 'elements',
    'template' => 'theme-test-render-element',
  );
  $items['theme_test_render_element_children'] = array(
    'render element' => 'element',
  );
  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.yml';
  $themes['test_basetheme'] = drupal_get_path('module', 'system') . '/tests/themes/test_basetheme/test_basetheme.info.yml';
  $themes['test_subtheme'] = drupal_get_path('module', 'system') . '/tests/themes/test_subtheme/test_subtheme.info.yml';
  $themes['test_theme_phptemplate'] = drupal_get_path('module', 'system') . '/tests/themes/test_theme_phptemplate/test_theme_phptemplate.info.yml';
  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/request-listener'] = array(
    'page callback' => 'theme_test_request_listener_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,
  );
  $items['theme-test/info/stylesheets'] = array(
    'page callback' => 'theme_test_info_stylesheets',
    'access callback' => TRUE,
    'type' => MENU_CALLBACK,
  );
  return $items;
}

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

/**
 * Menu callback for testing themed output generated in a request listener.
 */
function theme_test_request_listener_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');
}

/**
 * Page callback; Adds stylesheets to test theme .info.yml property processing.
 *
 * @see test_basetheme.info.yml
 * @see test_subtheme.info.yml
 * @see \Drupal\system\Tests\Theme\ThemeInfoStylesTest
 * @see http://drupal.org/node/967266#comment-3689670
 */
function theme_test_info_stylesheets() {
  $path = drupal_get_path('module', 'theme_test');
  drupal_add_css("{$path}/css/base-override.css");
  drupal_add_css("{$path}/css/base-override.sub-remove.css");
  drupal_add_css("{$path}/css/base-remove.css");
  drupal_add_css("{$path}/css/base-remove.sub-override.css");
  drupal_add_css("{$path}/css/sub-override.css");
  drupal_add_css("{$path}/css/sub-remove.css");
  return '';
}

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

/**
 * Process variables for theme-test-render-element.tpl.php.
 */
function template_preprocess_theme_test_render_element(&$variables) {
  $variables['attributes']['data-variables-are-preprocessed'] = TRUE;
}

/**
 * Theme function for testing rendering of child elements via drupal_render().
 *
 * Theme hooks defining a 'render element' add an internal '#render_children'
 * property. When this property is found, drupal_render() avoids calling theme()
 * on the top-level element to prevent infinite recursion.
 *
 * @param array $variables
 *   An associative array containing:
 *   - element: An associative array containing the properties of the element.
 */
function theme_theme_test_render_element_children($variables) {
  return drupal_render($variables['element']);
}

Functions

Namesort descending Description
template_preprocess_theme_test_render_element Process variables for theme-test-render-element.tpl.php.
theme_test_info_stylesheets Page callback; Adds stylesheets to test theme .info.yml property processing.
theme_test_menu Implements hook_menu().
theme_test_preprocess_html Implements hook_preprocess_HOOK() for html.tpl.php.
theme_test_request_listener_page_callback Menu callback for testing themed output generated in a request listener.
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_theme_test_render_element_children Theme function for testing rendering of child elements via drupal_render().
_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.