diff options
author | Dries Buytaert <dries@buytaert.net> | 2007-06-28 07:48:41 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2007-06-28 07:48:41 +0000 |
commit | 2bf7c1c0e39c657db47607bb7ecdf95753ae15b4 (patch) | |
tree | 226e9b297f1de7747c7a839ff5313d9808ec2d16 | |
parent | ef9f10dba64525b7059c4695795a4b787ed4a7a4 (diff) | |
download | brdo-2bf7c1c0e39c657db47607bb7ecdf95753ae15b4.tar.gz brdo-2bf7c1c0e39c657db47607bb7ecdf95753ae15b4.tar.bz2 |
- Patch #147662 by Gordon et al: add new #pre_render callback to drupal_render().
-rw-r--r-- | includes/common.inc | 33 | ||||
-rw-r--r-- | includes/form.inc | 1 | ||||
-rw-r--r-- | includes/locale.inc | 8 | ||||
-rw-r--r-- | includes/mail.inc | 4 | ||||
-rw-r--r-- | modules/node/node.module | 2 | ||||
-rw-r--r-- | modules/user/user.module | 6 |
6 files changed, 42 insertions, 12 deletions
diff --git a/includes/common.inc b/includes/common.inc index 9ed8b2f3f..a5aa7361f 100644 --- a/includes/common.inc +++ b/includes/common.inc @@ -403,6 +403,7 @@ function drupal_http_request($url, $headers = array(), $method = 'GET', $data = // Parse the URL, and make sure we can handle the schema. $uri = parse_url($url); + switch ($uri['scheme']) { case 'http': $port = isset($uri['port']) ? $uri['port'] : 80; @@ -2483,6 +2484,25 @@ function drupal_render(&$elements) { return NULL; } + // If the default values for this element haven't been loaded yet, populate + // them. + if (!isset($elements['#defaults_loaded']) || !$elements['#defaults_loaded']) { + if ((!empty($elements['#type'])) && ($info = _element_info($elements['#type']))) { + $elements += $info; + } + } + + // Make any final changes to the element before it is rendered. This means + // that the $element or the chilren 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 (function_exists($function)) { + $elements = $function($elements); + } + } + } + $content = ''; // Either the elements did not go through form_builder or one of the children // has a #weight. @@ -2534,6 +2554,16 @@ function drupal_render(&$elements) { } if (isset($content) && $content !== '') { + // Filter the outputed 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 (function_exists($function)) { + $content = $function($content, $elements); + } + } + } $prefix = isset($elements['#prefix']) ? $elements['#prefix'] : ''; $suffix = isset($elements['#suffix']) ? $elements['#suffix'] : ''; return $prefix . $content . $suffix; @@ -2835,7 +2865,7 @@ function drupal_delete_add_query($query) { * 'question' => Optional. The question for the confirm form. * 'destination' => Optional. The destination path for form submissions and form cancellations. * - * Also, any valid options from the $options argument of confirm_form() may + * Also, any valid options from the $options argument of confirm_form() may * be passed, and they will be passed through to the confirm form. */ function drupal_delete_confirm($confirm) { @@ -3450,4 +3480,3 @@ function watchdog_severity_levels() { WATCHDOG_DEBUG => t('debug'), ); } - diff --git a/includes/form.inc b/includes/form.inc index fb7bf1724..b9648e236 100644 --- a/includes/form.inc +++ b/includes/form.inc @@ -699,6 +699,7 @@ function form_builder($form_id, $form, &$form_state) { if (isset($form['#input']) && $form['#input']) { _form_builder_handle_input_element($form_id, $form, $form_state); } + $form['#defaults_loaded'] = TRUE; // We start off assuming all form elements are in the correct order. $form['#sorted'] = TRUE; diff --git a/includes/locale.inc b/includes/locale.inc index 9e9c11057..8c364e958 100644 --- a/includes/locale.inc +++ b/includes/locale.inc @@ -1726,7 +1726,7 @@ function _locale_export_get_strings($language = NULL, $group = 'default') { /** * Generates the PO(T) file contents for given strings. - * + * * @param $language * Language object to generate the output for, or NULL if generating * translation template. @@ -1739,7 +1739,7 @@ function _locale_export_get_strings($language = NULL, $group = 'default') { */ function _locale_export_po_generate($language = NULL, $strings = array(), $header = NULL) { global $user; - + if (!isset($header)) { if (isset($language)) { $header = '# '. $language->name .' translation of '. variable_get('site_name', 'Drupal') ."\n"; @@ -1776,9 +1776,9 @@ function _locale_export_po_generate($language = NULL, $strings = array(), $heade $header .= "\"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\\n\"\n"; } } - + $output = $header ."\n"; - + foreach ($strings as $lid => $string) { // Only process non-children, children are output below their parent. if (!isset($string['child'])) { diff --git a/includes/mail.inc b/includes/mail.inc index 283dd2f04..05fa4411a 100644 --- a/includes/mail.inc +++ b/includes/mail.inc @@ -277,7 +277,7 @@ function drupal_html_to_text($string, $allowed_tags = NULL) { } // Process blocks of text. else { - // Convert inline HTML text to plain text. + // Convert inline HTML text to plain text. $value = trim(preg_replace('/\s+/', ' ', decode_entities($value))); if (strlen($value)) { $chunk = $value; @@ -295,7 +295,7 @@ function drupal_html_to_text($string, $allowed_tags = NULL) { // Remove non-quotation markers from indentation. $indent = array_map('_drupal_html_to_text_clean', $indent); } - + $tag = !$tag; } diff --git a/modules/node/node.module b/modules/node/node.module index 02f2eae2b..c8b2208f4 100644 --- a/modules/node/node.module +++ b/modules/node/node.module @@ -3091,7 +3091,7 @@ function node_content_access($op, $node) { return TRUE; } } - + if ($op == 'delete') { if (user_access('delete '. $type .' content') || (user_access('delete own '. $type .' content') && ($user->uid == $node->uid))) { return TRUE; diff --git a/modules/user/user.module b/modules/user/user.module index f9b5d69b5..ca4c2856e 100644 --- a/modules/user/user.module +++ b/modules/user/user.module @@ -522,13 +522,13 @@ function user_search($op = 'search', $keys = NULL, $skip_access_check = FALSE) { // Administrators can also search in the otherwise private email field. $result = pager_query("SELECT name, uid, mail FROM {users} WHERE LOWER(name) LIKE LOWER('%%%s%%') OR LOWER(mail) LIKE LOWER('%%%s%%')", 15, 0, NULL, $keys, $keys); while ($account = db_fetch_object($result)) { - $find[] = array('title' => $account->name .' ('. $account->mail .')', 'link' => url('user/'. $account->uid, array('absolute' => TRUE))); + $find[] = array('title' => $account->name .' ('. $account->mail .')', 'link' => url('user/'. $account->uid, array('absolute' => TRUE))); } } else { - $result = pager_query("SELECT name, uid FROM {users} WHERE LOWER(name) LIKE LOWER('%%%s%%')", 15, 0, NULL, $keys); + $result = pager_query("SELECT name, uid FROM {users} WHERE LOWER(name) LIKE LOWER('%%%s%%')", 15, 0, NULL, $keys); while ($account = db_fetch_object($result)) { - $find[] = array('title' => $account->name, 'link' => url('user/'. $account->uid, array('absolute' => TRUE))); + $find[] = array('title' => $account->name, 'link' => url('user/'. $account->uid, array('absolute' => TRUE))); } } return $find; |