summaryrefslogtreecommitdiff
path: root/includes
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2006-08-10 15:42:33 +0000
committerDries Buytaert <dries@buytaert.net>2006-08-10 15:42:33 +0000
commitce85b7c7f806126f6c4487cde54a990cfa8d1eba (patch)
tree30d6bd007dc5b3f754dbbc575ffc4bd3c55a0c62 /includes
parentba9f7f17946e35bac44c4dbdbef3bcd8d9a8e8f9 (diff)
downloadbrdo-ce85b7c7f806126f6c4487cde54a990cfa8d1eba.tar.gz
brdo-ce85b7c7f806126f6c4487cde54a990cfa8d1eba.tar.bz2
- Patch #74326 by Eaton, Royboy, chx, et al: building $node->body with arrays like FAPI for viewing.
Once again, we're paving the path for CCK in core ... :)
Diffstat (limited to 'includes')
-rw-r--r--includes/common.inc113
-rw-r--r--includes/form.inc106
-rw-r--r--includes/locale.inc4
3 files changed, 116 insertions, 107 deletions
diff --git a/includes/common.inc b/includes/common.inc
index af3371cc2..cd63bcc55 100644
--- a/includes/common.inc
+++ b/includes/common.inc
@@ -1570,3 +1570,116 @@ function drupal_cron_run() {
// Return TRUE so other functions can check if it did run successfully
return TRUE;
}
+
+/**
+ * Renders HTML given a structured array tree. Recursively iterates over each
+ * of the array elements, generating HTML code. This function is usually
+ * called from within a another function, like drupal_get_form() or node_view().
+ *
+ * @param $elements
+ * The structured array describing the data to be rendered.
+ * @return
+ * The rendered HTML.
+ */
+function drupal_render(&$elements) {
+ if (!isset($elements)) {
+ return NULL;
+ }
+ $content = '';
+ uasort($elements, "_element_sort");
+ if (!isset($elements['#children'])) {
+ $children = element_children($elements);
+ /* Render all the children that use a theme function */
+ if (isset($elements['#theme']) && !$elements['#theme_used']) {
+ $elements['#theme_used'] = TRUE;
+
+ $previous_value = $elements['#value'];
+ $previous_type = $elements['#type'];
+ // If we rendered a single element, then we will skip the renderer.
+ if (empty($children)) {
+ $elements['#printed'] = TRUE;
+ }
+ else {
+ $elements['#value'] = '';
+ }
+ $elements['#type'] = 'markup';
+
+ $content = theme($elements['#theme'], $elements);
+
+ $elements['#value'] = $previous_value;
+ $elements['#type'] = $previous_type;
+ unset($elements['#prefix'], $elements['#suffix']);
+ }
+ /* render each of the children using drupal_render and concatenate them */
+ if (!isset($content) || $content === '') {
+ foreach ($children as $key) {
+ $content .= drupal_render($elements[$key]);
+ }
+ }
+ }
+ if (isset($content) && $content !== '') {
+ $elements['#children'] = $content;
+ }
+
+ // Until now, we rendered the children, here we render the element itself
+ if (!isset($elements['#printed'])) {
+ $content = theme(($elements['#type']) ? $elements['#type']: 'markup', $elements);
+ $elements['#printed'] = TRUE;
+ }
+
+ if (isset($content) && $content !== '') {
+ $prefix = isset($elements['#prefix']) ? $elements['#prefix'] : '';
+ $suffix = isset($elements['#suffix']) ? $elements['#suffix'] : '';
+ $content = $prefix . $content . $suffix;
+
+ if (isset($elements['#after_render'])) {
+ foreach ($elements['#after_render'] as $function) {
+ $function($elements, $content);
+ }
+ }
+
+ return $content;
+ }
+}
+
+/**
+ * Function used by uasort in drupal_render() to sort structured arrays
+ * by weight.
+ */
+function _element_sort($a, $b) {
+ $a_weight = (is_array($a) && isset($a['#weight'])) ? $a['#weight'] : 0;
+ $b_weight = (is_array($b) && isset($b['#weight'])) ? $b['#weight'] : 0;
+ if ($a_weight == $b_weight) {
+ return 0;
+ }
+ return ($a_weight < $b_weight) ? -1 : 1;
+}
+
+/**
+ * Check if the key is a property.
+ */
+function element_property($key) {
+ return $key[0] == '#';
+}
+
+/**
+ * Get properties of a structured array element. Properties begin with '#'.
+ */
+function element_properties($element) {
+ return array_filter(array_keys((array) $element), 'element_property');
+}
+
+/**
+ * Check if the key is a child.
+ */
+function element_child($key) {
+ return $key[0] != '#';
+}
+
+/**
+ * Get keys of a structured array tree element that are not properties
+ * (i.e., do not begin with '#').
+ */
+function element_children($element) {
+ return array_filter(array_keys((array) $element), 'element_child');
+} \ No newline at end of file
diff --git a/includes/form.inc b/includes/form.inc
index 45df7f9fa..3fe498406 100644
--- a/includes/form.inc
+++ b/includes/form.inc
@@ -15,34 +15,6 @@
*/
/**
- * Check if the key is a property.
- */
-function element_property($key) {
- return $key[0] == '#';
-}
-
-/**
- * Get properties of a form tree element. Properties begin with '#'.
- */
-function element_properties($element) {
- return array_filter(array_keys((array) $element), 'element_property');
-}
-
-/**
- * Check if the key is a child.
- */
-function element_child($key) {
- return $key[0] != '#';
-}
-
-/**
- * Get keys of a form tree element that are not properties (i.e., do not begin with '#').
- */
-function element_children($element) {
- return array_filter(array_keys((array) $element), 'element_child');
-}
-
-/**
* Processes a form array and produces the HTML output of a form.
* If there is input in the $_POST['edit'] variable, this function
* will attempt to validate it, using drupal_validate_form(),
@@ -263,7 +235,7 @@ function drupal_render_form($form_id, &$form, $callback = NULL) {
}
}
- $output = form_render($form);
+ $output = drupal_render($form);
return $output;
}
@@ -589,82 +561,6 @@ function _form_set_value(&$form_values, $form, $parents, $value) {
}
/**
- * Renders a HTML form given a form tree. Recursively iterates over each of
- * the form elements, generating HTML code. This function is usually
- * called from within a theme. To render a form from within a module, use
- * drupal_get_form().
- *
- * @param $elements
- * The form tree describing the form.
- * @return
- * The rendered HTML form.
- */
-function form_render(&$elements) {
- if (!isset($elements)) {
- return NULL;
- }
- $content = '';
- uasort($elements, "_form_sort");
- if (!isset($elements['#children'])) {
- $children = element_children($elements);
- /* Render all the children that use a theme function */
- if (isset($elements['#theme']) && !$elements['#theme_used']) {
- $elements['#theme_used'] = TRUE;
-
- $previous_value = $elements['#value'];
- $previous_type = $elements['#type'];
- // If we rendered a single element, then we will skip the renderer.
- if (empty($children)) {
- $elements['#printed'] = TRUE;
- }
- else {
- $elements['#value'] = '';
- }
- $elements['#type'] = 'markup';
-
- $content = theme($elements['#theme'], $elements);
-
- $elements['#value'] = $previous_value;
- $elements['#type'] = $previous_type;
- unset($elements['#prefix'], $elements['#suffix']);
- }
- /* render each of the children using form_render and concatenate them */
- if (!isset($content) || $content === '') {
- foreach ($children as $key) {
- $content .= form_render($elements[$key]);
- }
- }
- }
- if (isset($content) && $content !== '') {
- $elements['#children'] = $content;
- }
-
- // Until now, we rendered the children, here we render the element itself
- if (!isset($elements['#printed'])) {
- $content = theme(($elements['#type']) ? $elements['#type']: 'markup', $elements);
- $elements['#printed'] = TRUE;
- }
-
- if (isset($content) && $content !== '') {
- $prefix = isset($elements['#prefix']) ? $elements['#prefix'] : '';
- $suffix = isset($elements['#suffix']) ? $elements['#suffix'] : '';
- return $prefix . $content . $suffix;
- }
-}
-
-/**
- * Function used by uasort in form_render() to sort form by weight.
- */
-function _form_sort($a, $b) {
- $a_weight = (is_array($a) && isset($a['#weight'])) ? $a['#weight'] : 0;
- $b_weight = (is_array($b) && isset($b['#weight'])) ? $b['#weight'] : 0;
- if ($a_weight == $b_weight) {
- return 0;
- }
- return ($a_weight < $b_weight) ? -1 : 1;
-}
-
-/**
* Retrieve the default properties for the defined element type.
*/
function _element_info($type, $refresh = NULL) {
diff --git a/includes/locale.inc b/includes/locale.inc
index 7fa3aa9c3..ff4232143 100644
--- a/includes/locale.inc
+++ b/includes/locale.inc
@@ -86,12 +86,12 @@ function theme_locale_admin_manage_screen($form) {
foreach ($form['name'] as $key => $element) {
// Do not take form control structures.
if (is_array($element) && element_child($key)) {
- $rows[] = array(check_plain($key), form_render($form['name'][$key]), form_render($form['enabled'][$key]), form_render($form['site_default'][$key]), ($key != 'en' ? form_render($form['translation'][$key]) : t('n/a')), ($key != 'en' ? l(t('delete'), 'admin/settings/locale/language/delete/'. $key) : ''));
+ $rows[] = array(check_plain($key), drupal_render($form['name'][$key]), drupal_render($form['enabled'][$key]), drupal_render($form['site_default'][$key]), ($key != 'en' ? drupal_render($form['translation'][$key]) : t('n/a')), ($key != 'en' ? l(t('delete'), 'admin/settings/locale/language/delete/'. $key) : ''));
}
}
$header = array(array('data' => t('Code')), array('data' => t('English name')), array('data' => t('Enabled')), array('data' => t('Default')), array('data' => t('Translated')), array('data' => t('Operations')));
$output = theme('table', $header, $rows);
- $output .= form_render($form);
+ $output .= drupal_render($form);
return $output;
}