cms/drupal/modules/simpletest/tests/theme_test.module
changeset 541 e756a8c72c3d
equal deleted inserted replaced
540:07239de796bb 541:e756a8c72c3d
       
     1 <?php
       
     2 
       
     3 /**
       
     4  * Implements hook_theme().
       
     5  */
       
     6 function theme_test_theme($existing, $type, $theme, $path) {
       
     7   $items['theme_test'] = array(
       
     8     'file' => 'theme_test.inc',
       
     9     'variables' => array('foo' => ''),
       
    10   );
       
    11   $items['theme_test_template_test'] = array(
       
    12     'template' => 'theme_test.template_test',
       
    13   );
       
    14   $items['theme_test_template_test_2'] = array(
       
    15     'template' => 'theme_test.template_test',
       
    16   );
       
    17   $items['theme_test_foo'] = array(
       
    18     'variables' => array('foo' => NULL),
       
    19   );
       
    20   return $items;
       
    21 }
       
    22 
       
    23 /**
       
    24  * Implements hook_system_theme_info().
       
    25  */
       
    26 function theme_test_system_theme_info() {
       
    27   $themes['test_theme'] = drupal_get_path('module', 'theme_test') . '/themes/test_theme/test_theme.info';
       
    28   $themes['test_basetheme'] = drupal_get_path('module', 'theme_test') . '/themes/test_basetheme/test_basetheme.info';
       
    29   $themes['test_subtheme'] = drupal_get_path('module', 'theme_test') . '/themes/test_subtheme/test_subtheme.info';
       
    30   $themes['test_theme_nyan_cat'] = drupal_get_path('module', 'theme_test') . '/themes/test_theme_nyan_cat/test_theme_nyan_cat.info';
       
    31   return $themes;
       
    32 }
       
    33 
       
    34 /**
       
    35  * Implements hook_system_theme_engine_info().
       
    36  */
       
    37 function theme_test_system_theme_engine_info() {
       
    38   $theme_engines['nyan_cat'] = drupal_get_path('module', 'theme_test') . '/themes/engines/nyan_cat/nyan_cat.engine';
       
    39   return $theme_engines;
       
    40 }
       
    41 
       
    42 /**
       
    43  * Implements hook_menu().
       
    44  */
       
    45 function theme_test_menu() {
       
    46   $items['theme-test/suggestion'] = array(
       
    47     'title' => 'Suggestion',
       
    48     'page callback' => '_theme_test_suggestion',
       
    49     'access arguments' => array('access content'),
       
    50     'theme callback' => '_theme_custom_theme',
       
    51     'type' => MENU_CALLBACK,
       
    52   );
       
    53   $items['theme-test/alter'] = array(
       
    54     'title' => 'Suggestion',
       
    55     'page callback' => '_theme_test_alter',
       
    56     'access arguments' => array('access content'),
       
    57     'theme callback' => '_theme_custom_theme',
       
    58     'type' => MENU_CALLBACK,
       
    59   );
       
    60   $items['theme-test/hook-init'] = array(
       
    61     'page callback' => 'theme_test_hook_init_page_callback',
       
    62     'access callback' => TRUE,
       
    63     'type' => MENU_CALLBACK,
       
    64   );
       
    65   $items['theme-test/drupal-add-region-content'] = array(
       
    66     'page callback' => '_theme_test_drupal_add_region_content',
       
    67     'access callback' => TRUE,
       
    68     'type' => MENU_CALLBACK,
       
    69   );
       
    70   $items['theme-test/engine-info-test'] = array(
       
    71     'description' => "Serves a simple page rendered using a Nyan Cat theme engine template.",
       
    72     'page callback' => '_theme_test_engine_info_test',
       
    73     'access callback' => TRUE,
       
    74     'type' => MENU_CALLBACK,
       
    75   );
       
    76   return $items;
       
    77 }
       
    78 
       
    79 /**
       
    80  * Implements hook_init().
       
    81  */
       
    82 function theme_test_init() {
       
    83   if (arg(0) == 'theme-test' && arg(1) == 'hook-init') {
       
    84     // First, force the theme registry to be rebuilt on this page request. This
       
    85     // allows us to test a full initialization of the theme system in the code
       
    86     // below.
       
    87     drupal_theme_rebuild();
       
    88     // Next, initialize the theme system by storing themed text in a global
       
    89     // variable. We will use this later in theme_test_hook_init_page_callback()
       
    90     // to test that even when the theme system is initialized this early, it is
       
    91     // still capable of returning output and theming the page as a whole.
       
    92     $GLOBALS['theme_test_output'] = theme('more_link', array('url' => 'user', 'title' => 'Themed output generated in hook_init()'));
       
    93   }
       
    94 }
       
    95 
       
    96 /**
       
    97  * Implements hook_exit().
       
    98  */
       
    99 function theme_test_exit() {
       
   100   if (arg(0) == 'user') {
       
   101     // Register a fake registry loading callback. If it gets called by
       
   102     // theme_get_registry(), the registry has not been initialized yet.
       
   103     _theme_registry_callback('_theme_test_load_registry', array());
       
   104     print theme_get_registry() ? 'registry initialized' : 'registry not initialized';
       
   105   }
       
   106 }
       
   107 
       
   108 /**
       
   109  * Fake registry loading callback.
       
   110  */
       
   111 function _theme_test_load_registry() {
       
   112   return array();
       
   113 }
       
   114 
       
   115 /**
       
   116  * Menu callback for testing themed output generated in hook_init().
       
   117  */
       
   118 function theme_test_hook_init_page_callback() {
       
   119   return $GLOBALS['theme_test_output'];
       
   120 }
       
   121 
       
   122 /**
       
   123  * Custom theme callback.
       
   124  */
       
   125 function _theme_custom_theme() {
       
   126   return 'test_theme';
       
   127 }
       
   128 
       
   129 /**
       
   130  * Page callback, calls drupal_alter().
       
   131  *
       
   132  * This is for testing that the theme can have hook_*_alter() implementations
       
   133  * that run during page callback execution, even before theme() is called for
       
   134  * the first time.
       
   135  */
       
   136 function _theme_test_alter() {
       
   137   $data = 'foo';
       
   138   drupal_alter('theme_test_alter', $data);
       
   139   return "The altered data is $data.";
       
   140 }
       
   141 
       
   142 /**
       
   143  * Page callback, calls a theme hook suggestion.
       
   144  */
       
   145 function _theme_test_suggestion() {
       
   146   return theme(array('theme_test__suggestion', 'theme_test'), array());
       
   147 }
       
   148 
       
   149 /**
       
   150  * Page callback, calls drupal_add_region_content.
       
   151  */
       
   152 function _theme_test_drupal_add_region_content() {
       
   153   drupal_add_region_content('content', 'World');
       
   154   return 'Hello';
       
   155 }
       
   156 
       
   157 /**
       
   158  * Serves a simple page renderered using a Nyan Cat theme engine template.
       
   159  */
       
   160 function _theme_test_engine_info_test() {
       
   161   return array(
       
   162     '#markup' => theme('theme_test_template_test'),
       
   163   );
       
   164 }
       
   165 
       
   166 /**
       
   167  * Theme function for testing theme('theme_test_foo').
       
   168  */
       
   169 function theme_theme_test_foo($variables) {
       
   170   return $variables['foo'];
       
   171 }