drupal_render

  1. drupal
    1. drupal6
    2. drupal7
Versionen
drupal6 – drupal7 drupal_render(&$elements)

Renders HTML given a structured array tree.

Recursively iterates over each of the array elements, generating HTML code.

HTML generation is controlled by two properties containing theme functions, #theme and #theme_wrapper.

#theme is the theme function called first. If it is set and the element has any children, they have to be rendered there. For elements that are not allowed to have any children, e.g. buttons or textfields, it can be used to render the element itself. If #theme is not present and the element has children, they are rendered and concatenated into a string by drupal_render_children().

The theme function in #theme_wrapper will be called after #theme has run. It can be used to add further markup around the rendered children, e.g. fieldsets add the required markup for a fieldset around their rendered child elements. A wrapper theme function always has to include the element's #children property in its output, as this contains the rendered children.

For example, for the form element type, by default only the #theme_wrapper property is set, which adds the form markup around the rendered child elements of the form. This allows you to set the #theme property on a specific form to a custom theme function, giving you complete control over the placement of the form's children while not at all having to deal with the form markup itself.

This function is usually called from within a another function, like drupal_get_form() or a theme function. Elements are sorted internally using uasort(). Since this is expensive, when passing already sorted elements to drupal_render(), for example from a database query, set $elements['#sorted'] = TRUE to avoid sorting them a second time.

Übergabeparameter

$elements The structured array describing the data to be rendered.

Rückgabewert

The rendered HTML.

▾ 68 functions call drupal_render()

book_form_update in modules/book/book.pages.inc
AJAX callback to replace the book parent select options.
book_node_export in modules/book/book.module
Generates printer-friendly HTML for a node.
comment_form_add_preview in modules/comment/comment.module
Form builder; Generate and validate a comment preview form.
comment_reply in modules/comment/comment.pages.inc
This function is responsible for generating a comment reply form. There are several cases that have to be handled, including:
DrupalRenderUnitTestCase::testDrupalRenderSorting in modules/simpletest/tests/common.test
Test sorting by weight.
drupal_render_children in includes/common.inc
Render children of an element and concatenate them.
drupal_render_page in includes/common.inc
Renders the page, including all theming.
FieldAttachTestCase::testFieldAttachViewAndPreprocess in modules/field/field.test
field_add_more_js in modules/field/field.form.inc
Menu callback for AHAH addition of new empty widgets.
hook_search in modules/search/search.api.php
Define a custom search routine.
install_change_settings in ./install.php
Configure and rewrite settings.php.
install_select_locale in ./install.php
Allow admin to select which locale to use for the current profile.
install_select_profile in ./install.php
Allow admin to select which profile to install.
install_tasks in ./install.php
Tasks performed after the database is initialized.
locale_translate_export_screen in includes/locale.inc
User interface for the translation export screen.
locale_translate_seek_screen in includes/locale.inc
String search screen.
node_feed in modules/node/node.module
A generic function for generating RSS feeds from a set of nodes.
node_search in modules/node/node.module
Implementation of hook_search().
node_unpublish_by_keyword_action in modules/node/node.module
Implementation of a configurable Drupal action. Unpublish a node if it contains a certain string.
openid_redirect in modules/openid/openid.inc
Creates a js auto-submit redirect for (for the 2.x protocol)
poll_choice_js in modules/poll/poll.module
Menu callback for AHAH additions. Render the new poll choices.
template_preprocess_block in modules/block/block.module
Process variables for block.tpl.php
template_preprocess_block_admin_display_form in modules/block/block.admin.inc
Process variables for block-admin-display.tpl.php.
template_preprocess_node in modules/node/node.module
Process variables for node.tpl.php
template_preprocess_page in includes/theme.inc
Process variables for page.tpl.php
template_preprocess_poll_vote in modules/poll/poll.module
Themes the voting form for a poll.
template_preprocess_search_block_form in modules/search/search.module
Process variables for search-block-form.tpl.php.
template_preprocess_search_theme_form in modules/search/search.module
Process variables for search-theme-form.tpl.php.
template_preprocess_user_profile in modules/user/user.pages.inc
Process variables for user-profile.tpl.php.
TextFieldTestCase::_testTextfieldWidgets in modules/field/modules/text/text.test
Helper function for testTextfieldWidgets().
TextFieldTestCase::_testTextfieldWidgetsFormatted in modules/field/modules/text/text.test
Helper function for testTextfieldWidgetsFormatted().
theme_aggregator_categorize_items in modules/aggregator/aggregator.pages.inc
Theme the page list form for assigning categories.
theme_book_admin_table in modules/book/book.admin.inc
Theme function for the book administration page form.
theme_color_scheme_form in modules/color/color.module
Theme the color form.
theme_comment_form_box in modules/comment/comment.module
Theme the comment form box.
theme_dblog_filters in modules/dblog/dblog.module
Theme dblog administration filter selector.
theme_field_multiple_value_form in modules/field/field.form.inc
Theme an individual form element.
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 admin overview form.
theme_locale_languages_overview_form in includes/locale.inc
Theme the language overview form.
theme_locale_translation_filters in modules/locale/locale.module
Theme locale translation filter selector.
theme_menu_overview_form in modules/menu/menu.admin.inc
Theme the menu overview form into a table.
theme_node_admin_nodes in modules/node/node.admin.inc
Theme node administration overview.
theme_node_filters in modules/node/node.admin.inc
Theme node administration filter selector.
theme_node_filter_form in modules/node/node.admin.inc
Theme node administration filter form.
theme_node_preview in modules/node/node.pages.inc
Display a node preview for display during node creation and editing.
theme_node_search_admin in modules/node/node.module
Theme the content ranking part of the search settings admin page.
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_simpletest_test_table in modules/simpletest/simpletest.pages.inc
Theme the test list generated by simpletest_test_form() into a table.
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_themes_form in modules/system/system.admin.inc
Theme function for the system themes form.
theme_system_theme_select_form in modules/system/system.admin.inc
Theme the theme select form.
theme_tableselect in includes/form.inc
Format a table with radio buttons or checkboxes.
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_upload_form_current in modules/upload/upload.module
Theme the attachments list.
theme_user_admin_account in modules/user/user.admin.inc
Theme user administration overview.
theme_user_admin_new_role in modules/user/user.admin.inc
Theme the new-role form.
theme_user_admin_perm in modules/user/user.admin.inc
Theme the administer permissions page.
theme_user_filters in modules/user/user.admin.inc
Theme user administration filter selector.
theme_user_filter_form in modules/user/user.admin.inc
Theme user administration filter form.
update_selection_page in ./update.php
UploadTestCase::testNodeUpload in modules/upload/upload.test
Create node; upload files to node; and edit, and delete uploads.
upload_js in modules/upload/upload.module
Menu-callback for JavaScript-based uploads.
user_external_login in modules/user/user.module
Perform standard Drupal login operations for a user object.
_node_index_node in modules/node/node.module
Index a single node.

Code

includes/common.inc, line 3589

<?php
function drupal_render(&$elements) {
  // Early-return nothing if user does not have access.
  if (!isset($elements) || (isset($elements['#access']) && !$elements['#access'])) {
    return;
  }

  // Do not print elements twice.
  if (isset($elements['#printed']) && $elements['#printed']) {
    return;
  }

  // If the default values for this element have not been loaded yet, populate
  // them.
  if (isset($elements['#type']) && empty($elements['#defaults_loaded'])) {
    $elements += element_info($elements['#type']);
  }
  else {
    $elements += element_basic_defaults();
  }

  // If #markup is not empty and no theme function is set, use theme_markup.
  // This allows to specify just #markup on an element without setting the #type.
  if (!empty($elements['#markup']) && empty($elements['#theme'])) {
    $elements['#theme'] = 'markup';
  }

  // Make any final changes to the element before it is rendered. This means
  // that the $element or the children can be altered or corrected before the
  // element is rendered into the final text.
  if (isset($elements['#pre_render'])) {
    foreach ($elements['#pre_render'] as $function) {
      if (drupal_function_exists($function)) {
        $elements = $function($elements);
      }
    }
  }

  // Add additional CSS and JavaScript files associated with this element.
  foreach (array('css', 'js') as $kind) {
    if (!empty($elements['#attached_' . $kind]) && is_array($elements['#attached_' . $kind])) {
      foreach ($elements['#attached_' . $kind] as $data => $options) {
        // If the value is not an array, it's a filename and passed as first
        // (and only) argument.
        if (!is_array($options)) {
          $data = $options;
          $options = NULL;
        }
        // When drupal_add_js with 'type' => 'setting' is called, the first
        // parameter ($data) is an array. Arrays can't be keys in PHP, so we
        // have to get $data from the value array.
        if (is_numeric($data)) {
          $data = $options['data'];
          unset($options['data']);
        }
        call_user_func('drupal_add_' . $kind, $data, $options);
      }
    }
  }

  // Get the children of the element, sorted by weight.
  $children = element_children($elements, TRUE);

  $elements['#children'] = '';
  // Call the element's #theme function if it is set. Then any children of the
  // element have to be rendered there.
  if (isset($elements['#theme'])) {
    $elements['#children'] = theme($elements['#theme'], $elements);
  }
  // If #theme was not set and the element has children, render them now
  // using drupal_render_children().
  if ($elements['#children'] == '') {
    $elements['#children'] = drupal_render_children($elements, $children);
  }

  // Let the theme function in #theme_wrapper add markup around the rendered
  // children.
  if (!empty($elements['#theme_wrapper'])) {
    $elements['#children'] = theme($elements['#theme_wrapper'], $elements);
  }

  // Filter the outputted content and make any last changes before the
  // content is sent to the browser. The changes are made on $content
  // which allows the output'ed text to be filtered.
  if (isset($elements['#post_render'])) {
    foreach ($elements['#post_render'] as $function) {
      if (drupal_function_exists($function)) {
        $elements['#children'] = $function($elements['#children'], $elements);
      }
    }
  }

  $prefix = isset($elements['#prefix']) ? $elements['#prefix'] : '';
  $suffix = isset($elements['#suffix']) ? $elements['#suffix'] : '';

  $elements['#printed'] = TRUE;
  return $prefix . $elements['#children'] . $suffix;
}
?>

Kommentare

Kommentar hinzufügen

Der Inhalt dieses Feldes wird nicht öffentlich zugänglich angezeigt.
  • Internet- und E-Mail-Adressen werden automatisch umgewandelt.
  • Zulässige HTML-Tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Zeilen und Absätze werden automatisch erzeugt.

Weitere Informationen über Formatierungsoptionen

Kommentar hinzufügen

Der Inhalt dieses Feldes wird nicht öffentlich zugänglich angezeigt.
  • Internet- und E-Mail-Adressen werden automatisch umgewandelt.
  • Zulässige HTML-Tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Zeilen und Absätze werden automatisch erzeugt.

Weitere Informationen über Formatierungsoptionen