theme

Versions
4.6 – 6
theme()
7
theme($hook, $variables = array())

Generate the themed output.

All requests for theme hooks must go through this function. It examines the request and routes it to the appropriate theme function. The theme registry is checked to determine which implementation to use, which may be a function or a template.

If the implementation is a template, the following functions may be used to modify the $variables array. They are processed in two distinct phases; "preprocess" and "process" functions. The order listed here is the order in which they execute.

  • template_preprocess(&$variables) This sets a default set of variables for all template implementations.
  • template_preprocess_HOOK(&$variables) This is the first preprocessor called specific to the hook; it should be implemented by the module that registers it.
  • MODULE_preprocess(&$variables) This will be called for all templates; it should only be used if there is a real need. It's purpose is similar to template_preprocess().
  • MODULE_preprocess_HOOK(&$variables) This is for modules that want to alter or provide extra variables for theming hooks not registered to itself. For example, if a module named "foo" wanted to alter the $classes_array variable for the hook "node" a preprocess function of foo_preprocess_node() can be created to intercept and alter the variable.
  • ENGINE_engine_preprocess(&$variables) This function should only be implemented by theme engines and exists so that it can set necessary variables for all hooks.
  • ENGINE_engine_preprocess_HOOK(&$variables) This is the same as the previous function, but it is called for a single theming hook.
  • THEME_preprocess(&$variables) This is for themes that want to alter or provide extra variables. For example, if a theme named "foo" wanted to alter the $classes_array variable for the hook "node" a preprocess function of foo_preprocess_node() can be created to intercept and alter the variable.
  • THEME_preprocess_HOOK(&$variables) The same applies from the previous function, but it is called for a specific hook.
  • template_process(&$variables) This sets a default set of variables for all template implementations.
  • template_process_HOOK(&$variables) This is the first processor called specific to the hook; it should be implemented by the module that registers it.
  • MODULE_process(&$variables) This will be called for all templates; it should only be used if there is a real need. It's purpose is similar to template_process().
  • MODULE_process_HOOK(&$variables) This is for modules that want to alter or provide extra variables for theming hooks not registered to itself. For example, if a module named "foo" wanted to alter the $classes_array variable for the hook "node" a process function of foo_process_node() can be created to intercept and alter the variable.
  • ENGINE_engine_process(&$variables) This function should only be implemented by theme engines and exists so that it can set necessary variables for all hooks.
  • ENGINE_engine_process_HOOK(&$variables) This is the same as the previous function, but it is called for a single theming hook.
  • ENGINE_process(&$variables) This is meant to be used by themes that utilize a theme engine. It is provided so that the processor is not locked into a specific theme. This makes it easy to share and transport code but theme authors must be careful to prevent fatal re-declaration errors when using sub-themes that have their own processor named exactly the same as its base theme. In the default theme engine (PHPTemplate), sub-themes will load their own template.php file in addition to the one used for its parent theme. This increases the risk for these errors. A good practice is to use the engine name for the base theme and the theme name for the sub-themes to minimize this possibility.
  • ENGINE_process_HOOK(&$variables) The same applies from the previous function, but it is called for a specific hook.
  • THEME_process(&$variables) These functions are based upon the raw theme; they should primarily be used by themes that do not use an engine or by sub-themes. It serves the same purpose as ENGINE_process().
  • THEME_process_HOOK(&$variables) The same applies from the previous function, but it is called for a specific hook.

If the implementation is a function, only the hook-specific preprocess and process functions (the ones ending in _HOOK) are called from the above list. This is because theme hooks with function implementations need to be fast, and calling the non-hook-specific preprocess and process functions for them would incur a noticeable performance penalty.

For template-implemented theme hooks, there are two special variables that these preprocess and process functions can set: 'template_file' and 'template_files'. These will be merged together to form a list of 'suggested' alternate template files to use, in reverse order of priority. template_file will always be a higher priority than items in template_files. theme() will then look for these files, one at a time, and use the first one that exists. If none exists, theme() will use the original registered file for the theme hook.

For function-implemented theme hooks, there are two special variables that these preprocess and process functions can set: 'theme_function' and 'theme_functions'. These will be merged together to form a list of 'suggested' alternate functions to use, in reverse order of priority. theme_function will always be a higher priority than items in theme_functions. theme() will then call the highest priority function that exists. If none exists, theme() will call the original registered function for the theme hook.

Parameters

$hook The name of the theme function to call. May be an array, in which case the first hook that actually has an implementation registered will be used. This can be used to choose 'fallback' theme implementations, so that if the specific theme hook isn't implemented anywhere, a more generic one will be used. This can allow themes to create specific theme implementations for named objects.

$variables An associative array of variables to merge with defaults from the theme registry, pass to preprocess and process functions for modification, and finally, pass to the function or template implementing the theme hook. Alternatively, this can be a renderable array, in which case, its properties are mapped to variables expected by the theme hook implementations.

Return value

An HTML string that generates the themed output.

▾ 203 functions call theme()

aggregator_aggregator_parse in modules/aggregator/aggregator.parser.inc
Implement hook_aggregator_parse().
aggregator_block_view in modules/aggregator/aggregator.module
Implement hook_block_view().
aggregator_categorize_items in modules/aggregator/aggregator.pages.inc
Form builder; build the page list form.
aggregator_page_categories in modules/aggregator/aggregator.pages.inc
Menu callback; displays all the categories used by the aggregator.
aggregator_page_opml in modules/aggregator/aggregator.pages.inc
Menu callback; generates an OPML representation of all feeds.
aggregator_page_rss in modules/aggregator/aggregator.pages.inc
Menu callback; generate an RSS 0.92 feed of aggregator items or categories.
aggregator_page_source in modules/aggregator/aggregator.pages.inc
Menu callback; displays all the items captured from a particular feed.
aggregator_page_sources in modules/aggregator/aggregator.pages.inc
Menu callback; displays all the feeds used by the aggregator.
blog_block_view in modules/blog/blog.module
Implement hook_block_view().
blog_page_user in modules/blog/blog.pages.inc
Menu callback; displays a Drupal page containing recent blog entries of a given user.
book_admin_overview in modules/book/book.admin.inc
Returns an administrative overview of all books.
book_block_view in modules/book/book.module
Implement hook_block_view().
book_export_html in modules/book/book.pages.inc
This function is called by book_export() to generate HTML for export.
book_node_export in modules/book/book.module
Generates printer-friendly HTML for a node.
book_node_view in modules/book/book.module
Implement hook_node_view().
book_render in modules/book/book.pages.inc
Menu callback; prints a listing of all books.
comment_admin_overview in modules/comment/comment.admin.inc
Form builder; Builds the comment overview form for the admin.
comment_block_view in modules/comment/comment.module
Implement hook_block_view().
comment_form in modules/comment/comment.module
Generate the basic commenting form, for appending to a node or display on a separate page.
comment_links in modules/comment/comment.module
Helper function, build links for an individual comment.
comment_node_view in modules/comment/comment.module
Implement hook_node_view().
contact_category_list in modules/contact/contact.admin.inc
Categories/list tab.
contact_personal_form in modules/contact/contact.pages.inc
Form builder; the personal contact form.
dashboard_show_disabled in modules/dashboard/dashboard.module
AJAX callback to show disabled blocks in the dashboard customization mode.
dblog_event in modules/dblog/dblog.admin.inc
Menu callback; displays details about a log message.
dblog_overview in modules/dblog/dblog.admin.inc
Menu callback; displays a listing of log messages.
drupal_add_feed in includes/common.inc
Add a feed URL for the current page.
drupal_deliver_html_page in includes/common.inc
Package and send the result of a page callback to the browser as a normal HTML page.
drupal_get_css in includes/common.inc
Returns a themed representation of all stylesheets that should be attached to the page.
drupal_get_js in includes/common.inc
Returns a themed presentation of all JavaScript code for the current page.
drupal_render in includes/common.inc
Renders HTML given a structured array tree.
field_format in modules/field/field.module
Format a field item for display.
field_ui_fields_list in modules/field_ui/field_ui.admin.inc
Menu callback; lists all defined fields for quick reference.
field_ui_inactive_message in modules/field_ui/field_ui.admin.inc
Helper function to display a message about inactive fields.
file_ajax_upload in modules/file/file.module
Menu callback; Shared AJAX callback for file uploads and deletions.
file_field_widget in modules/file/file.field.inc
Implementation of hook_field_widget().
file_managed_file_process in modules/file/file.module
Process function to expand the managed_file element type.
file_save_upload in includes/file.inc
Saves a file upload to a new location.
filter_admin_format_form in modules/filter/filter.admin.inc
Generate a text format form.
filter_admin_overview in modules/filter/filter.admin.inc
Menu callback; Displays a list of all text formats and allows them to be rearranged.
filter_form in modules/filter/filter.module
Generates a selector for choosing a format in a form.
filter_permission in modules/filter/filter.module
Implement hook_permission().
filter_tips_long in modules/filter/filter.pages.inc
Menu callback; show a page with long filter tips.
forum_block_view_pre_render in modules/forum/forum.module
A #pre_render callback. Lists nodes based on the element's #query property. *
forum_page in modules/forum/forum.pages.inc
Menu callback; prints a forum listing.
garland_preprocess_page in themes/garland/template.php
Override or insert variables into the page template.
help_page in modules/help/help.admin.inc
Menu callback; prints a page listing general help for a module.
hook_search_execute in modules/search/search.api.php
Execute a search for a set of key words.
hook_view in modules/node/node.api.php
Display a node.
image_field_widget in modules/image/image.field.inc
Implementation of hook_field_widget().
image_field_widget_process in modules/image/image.field.inc
An element #process callback for the image_image field type.
image_help in modules/image/image.module
Implement of hook_help().
image_style_form in modules/image/image.admin.inc
Form builder; Edit an image style name and effects order.
image_style_list in modules/image/image.admin.inc
Menu callback; Listing of all current image styles.
locale_block_view in modules/locale/locale.module
Implement hook_block_view().
locale_date_format_language_overview_page in modules/locale/locale.module
Display edit date format links for each language.
locale_translate_overview_screen in includes/locale.inc
Overview screen for translations.
menu_get_active_help in includes/menu.inc
Returns the help associated with the active menu item.
nodeapi_example_nodeapi in developer/examples/nodeapi_example.module
Implementation of hook_nodeapi().
node_add_page in modules/node/node.pages.inc
node_admin_content in modules/node/node.admin.inc
Menu callback: content administration.
node_admin_nodes in modules/node/node.admin.inc
Form builder: Builds the node administration overview.
node_block_view in modules/node/node.module
Implement hook_block_view().
node_example_view in developer/examples/node_example.module
Implementation of hook_view().
node_overview_types in modules/node/content_types.inc
Displays the content type admin overview page.
node_page_default in modules/node/node.module
Menu callback; Generate a listing of promoted nodes.
node_preview in modules/node/node.pages.inc
Generate a node preview.
node_revision_overview in modules/node/node.pages.inc
Generate an overview table of older revisions of a node.
node_search_execute in modules/node/node.module
Implement hook_search_execute().
node_title_list in modules/node/node.module
Gather a listing of links to nodes.
options_options in modules/field/modules/options/options.module
Helper function for finding the allowed values list for a field.
page_example_baz in developer/examples/page_example.module
A more complex page callback that takes arguments.
poll_page in modules/poll/poll.pages.inc
Menu callback to provide a simple list of all polls available.
poll_view_results in modules/poll/poll.module
Generates a graphical representation of the results of a poll.
poll_votes in modules/poll/poll.pages.inc
Callback for the 'votes' tab for polls you can see other votes on
profile_block_view in modules/profile/profile.module
Implement hook_block_view().
profile_browse in modules/profile/profile.pages.inc
Menu callback; display a list of user information.
rdf_process in modules/rdf/rdf.module
Template process function for adding extra tags to hold RDFa attributes.
scaffolding_example_overview_pager in developer/examples/scaffolding_example/scaffolding_example.admin.inc
Builds a sortable, paged overview of all records.
scaffolding_example_page in developer/examples/scaffolding_example/scaffolding_example.pages.inc
Build a simple listing page for records.
search_data in modules/search/search.module
Perform a standard search on the given keys, and return the formatted results.
seven_tablesort_indicator in themes/seven/template.php
Override of theme_tablesort_indicator().
simpletest_result_status_image in modules/simpletest/simpletest.pages.inc
Get the appropriate image for the status.
statistics_access_log in modules/statistics/statistics.admin.inc
Menu callback; Displays recent page accesses.
statistics_node_tracker in modules/statistics/statistics.pages.inc
statistics_recent_hits in modules/statistics/statistics.admin.inc
Menu callback; presents the "recent hits" page.
statistics_top_visitors in modules/statistics/statistics.admin.inc
Menu callback; presents the "top visitors" page.
syslog_watchdog in modules/syslog/syslog.module
Implement hook_watchdog().
system_actions_manage in modules/system/system.admin.inc
Menu callback; Displays an overview of available and configured actions.
system_admin_by_module in modules/system/system.admin.inc
Menu callback; prints a listing of admin tasks for each installed module.
system_admin_config_page in modules/system/system.admin.inc
Menu callback; Provide the administration overview page.
system_admin_menu_block_page in modules/system/system.admin.inc
Provide a single block from the administration menu as a page. This function is often a destination for these blocks. For example, 'admin/structure/types' needs to have a destination to be valid in the Drupal menu system, but too much...
system_block_view in modules/system/system.module
Implement hook_block_view().
system_main_admin_page in modules/system/system.admin.inc
Menu callback; Provide the administration overview page.
system_modules in modules/system/system.admin.inc
Menu callback; provides module enable/disable interface.
system_modules_confirm_form in modules/system/system.admin.inc
Display confirmation form for required modules.
system_modules_uninstall_confirm_form in modules/system/system.admin.inc
Confirm uninstall of selected modules.
system_page_build in modules/system/system.module
Implement hook_page_build().
system_settings_overview in modules/system/system.admin.inc
Menu callback; displays a module's settings page.
system_status in modules/system/system.admin.inc
Menu callback: displays the site status report. Can also be used as a pure check.
system_themes_form in modules/system/system.admin.inc
Menu callback; displays a listing of all themes.
t in includes/common.inc
Translate strings to the page language or a given language.
tablesort_header in includes/tablesort.inc
Format a column header.
taxonomy_term_page in modules/taxonomy/taxonomy.pages.inc
Menu callback; displays all nodes associated with a term.
template_preprocess_aggregator_feed_source in modules/aggregator/aggregator.pages.inc
Process variables for aggregator-feed-source.tpl.php.
template_preprocess_aggregator_summary_items in modules/aggregator/aggregator.pages.inc
Process variables for aggregator-summary-items.tpl.php.
template_preprocess_aggregator_wrapper in modules/aggregator/aggregator.pages.inc
Process variables for aggregator-wrapper.tpl.php.
template_preprocess_comment in modules/comment/comment.module
Process variables for comment.tpl.php.
template_preprocess_forums in modules/forum/forum.module
Process variables for forums.tpl.php
template_preprocess_forum_list in modules/forum/forum.module
Process variables to format a forum listing.
template_preprocess_forum_submitted in modules/forum/forum.module
Process variables to format submission info for display in the forum list and topic list.
template_preprocess_forum_topic_list in modules/forum/forum.module
Preprocess variables to format the topic listing.
template_preprocess_maintenance_page in includes/theme.inc
The variables generated here is a mirror of template_preprocess_page(). This preprocessor will run it's course when theme_maintenance_page() is invoked. It is also used in theme_install_page() and theme_update_page() to keep all the variables...
template_preprocess_node in modules/node/node.module
Process variables for node.tpl.php
template_preprocess_page in includes/theme.inc
Preprocess variables for page.tpl.php
template_preprocess_poll_results in modules/poll/poll.module
Preprocess the poll_results theme hook.
template_preprocess_profile_block in modules/profile/profile.module
Process variables for profile-block.tpl.php.
template_preprocess_profile_listing in modules/profile/profile.module
Process variables for profile-listing.tpl.php.
template_preprocess_search_results in modules/search/search.pages.inc
Process variables for search-results.tpl.php.
template_preprocess_user_picture in modules/user/user.module
Process variables for user-picture.tpl.php.
theme_admin_page in modules/system/system.admin.inc
This function formats an administrative page for viewing.
theme_aggregator_categorize_items in modules/aggregator/aggregator.pages.inc
Theme the page list form for assigning categories.
theme_authorize_report in includes/theme.maintenance.inc
Generate a report of the results from an operation run via authorize.php.
theme_book_admin_table in modules/book/book.admin.inc
Theme function for the book administration page form.
theme_comment_block in modules/comment/comment.module
Returns a formatted list of recent comments to be displayed in the comment block.
theme_dashboard_disabled_blocks in modules/dashboard/dashboard.module
Theme a set of disabled blocks, for display in dashboard customization mode.
theme_feed_icon in includes/theme.inc
Return code that emits an feed icon.
theme_field_formatter_file_default in modules/file/file.field.inc
Theme function for 'default' file field formatter.
theme_field_formatter_file_table in modules/file/file.field.inc
Theme function for the 'table' formatter.
theme_field_formatter_image in modules/image/image.field.inc
Theme function for 'image' image field formatter.
theme_field_formatter_image_link_content in modules/image/image.field.inc
Theme function for 'image_link_content' image field formatter.
theme_field_formatter_image_link_file in modules/image/image.field.inc
Theme function for 'image_link_file' image field formatter.
theme_field_multiple_value_form in modules/field/field.form.inc
Theme an individual form element.
theme_file_link in modules/file/file.module
Output a link to a file.
theme_file_widget_multiple in modules/file/file.field.inc
Theme a group of file upload widgets.
theme_filter_admin_order in modules/filter/filter.admin.inc
Theme filter order configuration form.
theme_filter_admin_overview in modules/filter/filter.admin.inc
Theme the text format administration overview form.
theme_filter_guidelines in modules/filter/filter.module
Format guidelines for a text format.
theme_form_element in includes/form.inc
Theme a form element.
theme_image_anchor in modules/image/image.admin.inc
Theme callback for displaying a grid of checkboxes.
theme_image_crop_summary in modules/image/image.admin.inc
Theme callback for image crop effect summary output.
theme_image_scale_summary in modules/image/image.admin.inc
Theme callback for image scale effect summary output.
theme_image_style in modules/image/image.module
Return a themed image using a specific image style.
theme_image_style_effects in modules/image/image.admin.inc
Theme callback for listing the effects within a specific image style.
theme_image_style_list in modules/image/image.admin.inc
Display the page containing the list of image styles.
theme_image_style_preview in modules/image/image.admin.inc
Theme callback for displaying a preview of an image style.
theme_install_page in includes/theme.maintenance.inc
Generate a themed installation page.
theme_locale_date_format_form in modules/locale/locale.module
Theme locale date format form.
theme_locale_languages_configure_form in includes/locale.inc
Theme the language configure form.
theme_locale_languages_overview_form in includes/locale.inc
Theme the language overview form.
theme_node_list in modules/node/node.module
Format a listing of links to nodes.
theme_node_search_admin in modules/node/node.module
Theme the content ranking part of the search settings admin page.
theme_pager in includes/pager.inc
Format a query pager.
theme_pager_first in includes/pager.inc
Format a "first page" link.
theme_pager_last in includes/pager.inc
Format a "last page" link.
theme_pager_next in includes/pager.inc
Format a "next page" link.
theme_pager_previous in includes/pager.inc
Format a "previous page" link.
theme_phonenumber in developer/examples/example_element.module
Theme function to format the output.
theme_poll_choices in modules/poll/poll.module
Theme the admin poll form for choices.
theme_profile_admin_overview in modules/profile/profile.admin.inc
Theme the profile field overview into a drag and drop enabled table.
theme_scaffolding_example_overview_form in developer/examples/scaffolding_example/scaffolding_example.admin.inc
Theme the drag-and-drop overview form.
theme_shortcut_set_customize in modules/shortcut/shortcut.admin.inc
Theme function for the shortcut set customization form.
theme_simpletest_test_table in modules/simpletest/simpletest.pages.inc
Theme the test list generated by simpletest_test_form() into a table.
theme_submit in includes/form.inc
Theme a submit button form element.
theme_system_admin_by_module in modules/system/system.admin.inc
Theme output of the dashboard page.
theme_system_date_time_settings in modules/system/system.admin.inc
Theme function for date settings form.
theme_system_modules_fieldset in modules/system/system.admin.inc
Theme callback for the modules form.
theme_system_modules_uninstall in modules/system/system.admin.inc
Themes a table of currently disabled modules.
theme_system_run_cron_image in modules/system/system.module
Display image used to run cron automatically.
theme_system_themes_form in modules/system/system.admin.inc
Theme function for the system themes form.
theme_tableselect in includes/form.inc
Format a table with radio buttons or checkboxes.
theme_tablesort_indicator in includes/theme.inc
Return a themed sort icon.
theme_taxonomy_overview_terms in modules/taxonomy/taxonomy.admin.inc
Theme the terms overview as a sortable list of terms.
theme_taxonomy_overview_vocabularies in modules/taxonomy/taxonomy.admin.inc
Theme the vocabulary overview as a sortable list of vocabularies.
theme_trigger_display in modules/trigger/trigger.admin.inc
Displays actions assigned to this hook in a table.
theme_update_manager_update_form in modules/update/update.manager.inc
Theme the first page in the update manager wizard to select projects.
theme_update_page in includes/theme.maintenance.inc
Generate a themed update page.
theme_update_report in modules/update/update.report.inc
Theme project status report.
theme_update_version in modules/update/update.report.inc
Theme the version display of a project.
theme_upload_attachments in modules/upload/upload.module
Displays file attachments in table
theme_upload_form_current in modules/upload/upload.module
Theme the attachments list.
theme_user_admin_new_role in modules/user/user.admin.inc
Theme the new-role form.
theme_user_admin_permissions in modules/user/user.admin.inc
Theme the administer permissions page.
theme_user_list in modules/user/user.module
Make a list of users.
tracker_page in modules/tracker/tracker.pages.inc
Menu callback; prints a listing of active nodes on the site.
update_manager_download_batch_finished in modules/update/update.manager.inc
Batch callback invoked when the download batch is completed.
update_manager_update_form in modules/update/update.manager.inc
Build the form for the update manager page to update existing projects.
update_status in modules/update/update.report.inc
Menu callback. Generate a page about the update status of projects.
upload_js in modules/upload/upload.module
Menu-callback for JavaScript-based uploads.
user_account_form in modules/user/user.module
Helper function to add default user account fields to user registration and edit form.
user_admin_account in modules/user/user.admin.inc
Form builder; User administration page.
user_block_view in modules/user/user.module
Implement hook_block_view().
user_login_block in modules/user/user.module
user_user_view in modules/user/user.module
Implement hook_user_view().
_aggregator_page_list in modules/aggregator/aggregator.pages.inc
Prints an aggregator page listing a number of feed items.
_batch_progress_page_nojs in includes/batch.inc
Output a batch processing page without JavaScript support.
_drupal_log_error in includes/common.inc
Log a PHP error or exception, display an error page in fatal cases.
_filter_html_tips in modules/filter/filter.module
Filter tips callback for HTML filter.
_locale_translate_seek in includes/locale.inc
Perform a string search and display results in a table
_node_mass_update_batch_finished in modules/node/node.admin.inc
Node Mass Update Batch 'finished' callback.
_scaffolding_example_record_links in developer/examples/scaffolding_example/scaffolding_example.admin.inc
Build the edit and delete links for a single record.
_simpletest_batch_operation in modules/simpletest/simpletest.module
Batch operation callback.
_system_modules_build_row in modules/system/system.admin.inc
Build a table row for the system modules page.

Code

includes/theme.inc, line 756

<?php
function theme($hook, $variables = array()) {
  static $hooks = NULL;
  if (!isset($hooks)) {
    drupal_theme_initialize();
    $hooks = theme_get_registry();
  }

  // If an array of hook candidates were passed, use the first one that has an
  // implementation.
  if (is_array($hook)) {
    foreach ($hook as $candidate) {
      if (isset($hooks[$candidate])) {
        break;
      }
    }
    $hook = $candidate;
  }

  if (!isset($hooks[$hook])) {
    watchdog('theme', 'Theme key "@key" not found.', array('@key' => $hook), WATCHDOG_WARNING);
    return '';
  }

  $info = $hooks[$hook];
  global $theme_path;
  $temp = $theme_path;
  // point path_to_theme() to the currently used theme path:
  $theme_path = $info['theme path'];

  // Include a file if the theme function or variable processor is held elsewhere.
  if (!empty($info['includes'])) {
    foreach ($info['includes'] as $include_file) {
      include_once DRUPAL_ROOT . '/' . $include_file;
    }
  }

  // If a renderable array is passed as $variables, then set $variables to
  // the arguments expected by the theme function.
  if (isset($variables['#theme']) || isset($variables['#theme_wrappers'])) {
    $element = $variables;
    $variables = array();
    if (isset($info['variables'])) {
      foreach (array_keys($info['variables']) as $name) {
        if (isset($element["#$name"])) {
          $variables[$name] = $element["#$name"];
        }
      }
    }
    else {
      $variables[$info['render element']] = $element;
    }
  }

  // Merge in argument defaults.
  if (!empty($info['variables'])) {
    $variables += $info['variables'];
  }
  elseif (!empty($info['render element'])) {
    $variables += array($info['render element'] => array());
  }

  // Invoke the variable processors, if any. The processors may specify
  // alternate suggestions for which function/template should be used.
  if (isset($info['preprocess functions']) || isset($info['process functions'])) {
    $variables['theme_functions'] = array();
    $variables['template_files'] = array();
    foreach (array('preprocess functions', 'process functions') as $phase) {
      if (!empty($info[$phase])) {
        foreach ($info[$phase] as $processor_function) {
          if (function_exists($processor_function)) {
            // We don't want a poorly behaved process function changing $hook.
            $hook_clone = $hook;
            $processor_function($variables, $hook_clone);
          }
        }
      }
    }
    // Function suggestion takes priority over template suggestion.
    // theme_function takes priority over theme_functions.
    // theme_functions are in FILO order (least appropriate to most appropriate).
    // Here, just look for function suggestions. Deal with template
    // suggestions only after determining that the theme call is a template.
    $suggestions = array();
    if (!empty($variables['theme_functions'])) {
      $suggestions = $variables['theme_functions'];
    }
    if (!empty($variables['theme_function'])) {
      $suggestions[] = $variables['theme_function'];
    }
    foreach (array_reverse($suggestions) as $suggestion) {
      if (function_exists($suggestion)) {
        $info['function'] = $suggestion;
        break;
      }
    }
  }

  // Generate the output using either a function or a template.
  if (isset($info['function'])) {
    if (function_exists($info['function'])) {
      $output = $info['function']($variables);
    }
  }
  else {
    // Default render function and extension.
    $render_function = 'theme_render_template';
    $extension = '.tpl.php';

    // Run through the theme engine variables, if necessary
    global $theme_engine;
    if (isset($theme_engine)) {
      // If theme or theme engine is implementing this, it may have
      // a different extension and a different renderer.
      if ($info['type'] != 'module') {
        if (function_exists($theme_engine . '_render_template')) {
          $render_function = $theme_engine . '_render_template';
        }
        $extension_function = $theme_engine . '_extension';
        if (function_exists($extension_function)) {
          $extension = $extension_function();
        }
      }
    }

    // Find which template file exists and can be used. Priority order is:
    // 1. $variables['template_file'].
    // 2. $variables['template_files'] in FILO order (later in array is higher
    //    priority).
    // 3. $info['template'].
    $suggestions = array();
    if (isset($variables['template_files'])) {
      $suggestions = $variables['template_files'];
    }
    if (isset($variables['template_file'])) {
      $suggestions[] = $variables['template_file'];
    }
    if ($suggestions) {
      $template_file = drupal_discover_template($info['theme paths'], $suggestions, $extension);
    }
    if (empty($template_file)) {
      $template_file = $info['template'] . $extension;
      if (isset($info['path'])) {
        $template_file = $info['path'] . '/' . $template_file;
      }
    }

    // Render the output using the found template file.
    $output = $render_function($template_file, $variables);
  }

  // restore path_to_theme()
  $theme_path = $temp;
  return $output;
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.