=== modified file 'includes/form.inc' --- includes/form.inc 2008-06-25 09:57:07 +0000 +++ includes/form.inc 2008-06-27 17:59:26 +0000 @@ -838,9 +838,18 @@ function form_error(&$element, $message * context, it is used to accumulate information about which button * was clicked when the form was submitted, as well as the sanitized * $_POST data. + * @param $parent_form + * The parent of this subform. */ -function form_builder($form_id, $form, &$form_state) { - static $complete_form, $cache; +function form_builder($form_id, $form, &$form_state, &$parent_form = array()) { + static $complete_form, $cache, $stored_form_id; + + if (!isset($form_id)) { + $form_id = $stored_form_id; + } + else { + $stored_form_id = $form_id; + } // Initialize as unprocessed. $form['#processed'] = FALSE; @@ -860,7 +869,7 @@ function form_builder($form_id, $form, & } if (isset($form['#input']) && $form['#input']) { - _form_builder_handle_input_element($form_id, $form, $form_state, $complete_form); + _form_builder_handle_input_element($form_id, $form, $form_state, $complete_form, $parent_form); } $form['#defaults_loaded'] = TRUE; @@ -868,41 +877,8 @@ function form_builder($form_id, $form, & $form['#sorted'] = TRUE; // Recurse through all child elements. - $count = 0; - foreach (element_children($form) as $key) { - $form[$key]['#post'] = $form['#post']; - $form[$key]['#programmed'] = $form['#programmed']; - // Don't squash an existing tree value. - if (!isset($form[$key]['#tree'])) { - $form[$key]['#tree'] = $form['#tree']; - } - - // Deny access to child elements if parent is denied. - if (isset($form['#access']) && !$form['#access']) { - $form[$key]['#access'] = FALSE; - } - - // Don't squash existing parents value. - if (!isset($form[$key]['#parents'])) { - // Check to see if a tree of child elements is present. If so, - // continue down the tree if required. - $form[$key]['#parents'] = $form[$key]['#tree'] && $form['#tree'] ? array_merge($form['#parents'], array($key)) : array($key); - $array_parents = isset($form['#array_parents']) ? $form['#array_parents'] : array(); - $array_parents[] = $key; - $form[$key]['#array_parents'] = $array_parents; - } - - // Assign a decimal placeholder weight to preserve original array order. - if (!isset($form[$key]['#weight'])) { - $form[$key]['#weight'] = $count/1000; - } - else { - // If one of the child elements has a weight then we will need to sort - // later. - unset($form['#sorted']); - } - $form[$key] = form_builder($form_id, $form[$key], $form_state); - $count++; + foreach (element_children($form) as $count => $key) { + _form_builder_handle_child($form, $form_state, $key, $count, $form_id); } // The #after_build flag allows any piece of a form to be altered @@ -939,11 +915,53 @@ function form_builder($form_id, $form, & } /** + * Handle a child element of a form. + * + * Inherits #post, #programmed, #tree, #parents, #array_parents and #weight + * properties to a child of the form and then calls form_builder on the child. + */ +function _form_builder_handle_child(&$form, &$form_state, $key, $count = 0, $form_id = NULL) { + $form[$key]['#post'] = $form['#post']; + $form[$key]['#programmed'] = $form['#programmed']; + // Don't squash an existing tree value. + if (!isset($form[$key]['#tree'])) { + $form[$key]['#tree'] = $form['#tree']; + } + + // Deny access to child elements if parent is denied. + if (isset($form['#access']) && !$form['#access']) { + $form[$key]['#access'] = FALSE; + } + + // Don't squash existing parents value. + if (!isset($form[$key]['#parents'])) { + // Check to see if a tree of child elements is present. If so, + // continue down the tree if required. + $form[$key]['#parents'] = $form[$key]['#tree'] && $form['#tree'] ? array_merge($form['#parents'], array($key)) : array($key); + $array_parents = isset($form['#array_parents']) ? $form['#array_parents'] : array(); + $array_parents[] = $key; + $form[$key]['#array_parents'] = $array_parents; + } + + // Assign a decimal placeholder weight to preserve original array order. + if (!isset($form[$key]['#weight'])) { + $form[$key]['#weight'] = $count/1000; + } + else { + // If one of the child elements has a weight then we will need to sort + // later. + unset($form['#sorted']); + } + + $form[$key] = form_builder($form_id, $form[$key], $form_state, $form); +} + +/** * Populate the #value and #name properties of input elements so they * can be processed and rendered. Also, execute any #process handlers * attached to a specific element. */ -function _form_builder_handle_input_element($form_id, &$form, &$form_state, $complete_form) { +function _form_builder_handle_input_element($form_id, &$form, &$form_state, $complete_form, &$parent_form) { if (!isset($form['#name'])) { $name = array_shift($form['#parents']); $form['#name'] = $name; @@ -1035,7 +1053,7 @@ function _form_builder_handle_input_elem if (isset($form['#process']) && !$form['#processed']) { foreach ($form['#process'] as $process) { if (drupal_function_exists($process)) { - $form = $process($form, isset($edit) ? $edit : NULL, $form_state, $complete_form); + $form = $process($form, isset($edit) ? $edit : NULL, $form_state, $complete_form, $parent_form); } } $form['#processed'] = TRUE; === modified file 'modules/filter/filter.module' --- modules/filter/filter.module 2008-05-06 12:18:44 +0000 +++ modules/filter/filter.module 2008-06-27 18:04:12 +0000 @@ -457,6 +457,19 @@ function check_markup($text, $format = F } /** + * Add a filter_form to a form. + */ +function filter_form_add($form, $edit, &$form_state, $complete_form, &$parent_form) { + if (isset($form['#input_format']) || array_key_exists('#input_format', $form)) { + $parents = $parent_form['#tree'] ? $parent_form['#parents'] : array(); + $parents[] = 'format'; + $parent_form['format'] = filter_form($form['#input_format'], $form['#weight'] + 1/10000, $parents); + _form_builder_handle_child($parent_form, $form_state, 'format'); + } + return $form; +} + +/** * Generate a selector for choosing a format in a form. * * @ingroup forms === modified file 'modules/node/node.pages.inc' --- modules/node/node.pages.inc 2008-04-14 17:48:33 +0000 +++ modules/node/node.pages.inc 2008-06-27 18:03:55 +0000 @@ -289,10 +289,9 @@ function node_body_field(&$node, $label, '#default_value' => $include ? $node->body : ($node->teaser . $node->body), '#rows' => 20, '#required' => ($word_count > 0), + '#input_format' => $node->format, ); - $form['format'] = filter_form($node->format); - return $form; } === modified file 'modules/system/system.module' --- modules/system/system.module 2008-06-25 09:12:24 +0000 +++ modules/system/system.module 2008-06-27 16:22:08 +0000 @@ -229,7 +229,7 @@ function system_elements() { '#cols' => 60, '#rows' => 5, '#resizable' => TRUE, - '#process' => array('form_expand_ahah'), + '#process' => array('form_expand_ahah', 'filter_form_add'), ); $type['radios'] = array(