Index: includes/form.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/form.inc,v retrieving revision 1.287 diff -u -p -r1.287 form.inc --- includes/form.inc 21 Sep 2008 06:34:41 -0000 1.287 +++ includes/form.inc 27 Sep 2008 04:59:24 -0000 @@ -1748,6 +1748,48 @@ function form_process_radios($element) { } /** + * Add an input format selector to form elements defining #input_format. + * + * If the property #input_format is set on elements of the type textarea or + * textfield, the original form element will be expanded into two separate form + * elements, while the value of the original element is submitted as is, i.e. + * not altered. This is done to allow an arbitrary input format widget in the + * resulting output, which can be simple markup or a list of available input + * formats the user is able to choose from. + * + * The form structure is altered, so the original element is expanded into two + * separate elements: the first array element, identified by the key 'value', + * is the original textarea/textfield element. The second array element, + * identified by the key 'format', contains the input format selector or simple + * markup for a single input format. + * The original element in the form structure is converted into a element of + * the type markup and does not output anything on its own. + * + * If the original form element was named 'body', it is submitted as is and on + * the same array level as if there was no input format. The additional input + * format value will be submitted as the original element name, plus suffix + * '_format', e.g. 'body_format'. + */ +function form_process_input_format($element) { + if (isset($element['#input_format'])) { + // Determine the form element parents and element name to use for the input + // format widget. + $format_parents = $element['#parents']; + $last_parent = array_pop($format_parents); + $format_parents[] = $last_parent .'_format'; + // We need to break references, otherwise form_builder recurses infinitely. + $element['value'] = (array)$element; + $element['#type'] = 'markup'; + $element['format'] = filter_form($element['#input_format'], 1, $format_parents); + // We need to clear the #input_format from the new child otherwise we + // would get into an infinite loop. + unset($element['value']['#input_format']); + $element['value']['#weight'] = 0; + } + return $element; +} + +/** * Add AHAH information about a form element to the page to communicate with * javascript. If #ahah[path] is set on an element, this additional javascript is * added to the page header to attach the AHAH behaviors. See ahah.js for more @@ -1787,6 +1829,8 @@ function form_process_ahah($element) { case 'select': $element['#ahah']['event'] = 'change'; break; + default: + return $element; } } Index: modules/block/block.module =================================================================== RCS file: /cvs/drupal/drupal/modules/block/block.module,v retrieving revision 1.309 diff -u -p -r1.309 block.module --- modules/block/block.module 21 Aug 2008 19:36:36 -0000 1.309 +++ modules/block/block.module 27 Sep 2008 04:03:42 -0000 @@ -315,24 +315,21 @@ function block_box_form($edit = array()) '#type' => 'textarea', '#title' => t('Block body'), '#default_value' => $edit['body'], + '#input_format' => isset($edit['format']) ? $edit['format'] : FILTER_FORMAT_DEFAULT, '#rows' => 15, '#description' => t('The content of the block as shown to the user.'), '#weight' => -17, ); - if (!isset($edit['format'])) { - $edit['format'] = FILTER_FORMAT_DEFAULT; - } - $form['body_field']['format'] = filter_form($edit['format'], -16); return $form; } function block_box_save($edit, $delta) { - if (!filter_access($edit['format'])) { - $edit['format'] = FILTER_FORMAT_DEFAULT; + if (!filter_access($edit['body_format'])) { + $edit['body_format'] = FILTER_FORMAT_DEFAULT; } - db_query("UPDATE {boxes} SET body = '%s', info = '%s', format = %d WHERE bid = %d", $edit['body'], $edit['info'], $edit['format'], $delta); + db_query("UPDATE {boxes} SET body = '%s', info = '%s', format = %d WHERE bid = %d", $edit['body'], $edit['info'], $edit['body_format'], $delta); return TRUE; } Index: modules/comment/comment.module =================================================================== RCS file: /cvs/drupal/drupal/modules/comment/comment.module,v retrieving revision 1.650 diff -u -p -r1.650 comment.module --- modules/comment/comment.module 17 Sep 2008 20:37:31 -0000 1.650 +++ modules/comment/comment.module 27 Sep 2008 04:03:42 -0000 @@ -666,7 +666,7 @@ function comment_save($edit) { ); if ($edit['cid']) { // Update the comment in the database. - db_query("UPDATE {comments} SET status = %d, timestamp = %d, subject = '%s', comment = '%s', format = %d, uid = %d, name = '%s', mail = '%s', homepage = '%s' WHERE cid = %d", $edit['status'], $edit['timestamp'], $edit['subject'], $edit['comment'], $edit['format'], $edit['uid'], $edit['name'], $edit['mail'], $edit['homepage'], $edit['cid']); + db_query("UPDATE {comments} SET status = %d, timestamp = %d, subject = '%s', comment = '%s', format = %d, uid = %d, name = '%s', mail = '%s', homepage = '%s' WHERE cid = %d", $edit['status'], $edit['timestamp'], $edit['subject'], $edit['comment'], $edit['comment_format'], $edit['uid'], $edit['name'], $edit['mail'], $edit['homepage'], $edit['cid']); // Allow modules to respond to the updating of a comment. comment_invoke_comment($edit, 'update'); // Add an entry to the watchdog log. @@ -719,7 +719,7 @@ function comment_save($edit) { $edit['name'] = $user->name; } - db_query("INSERT INTO {comments} (nid, pid, uid, subject, comment, format, hostname, timestamp, status, thread, name, mail, homepage) VALUES (%d, %d, %d, '%s', '%s', %d, '%s', %d, %d, '%s', '%s', '%s', '%s')", $edit['nid'], $edit['pid'], $edit['uid'], $edit['subject'], $edit['comment'], $edit['format'], ip_address(), $edit['timestamp'], $edit['status'], $thread, $edit['name'], $edit['mail'], $edit['homepage']); + db_query("INSERT INTO {comments} (nid, pid, uid, subject, comment, format, hostname, timestamp, status, thread, name, mail, homepage) VALUES (%d, %d, %d, '%s', '%s', %d, '%s', %d, %d, '%s', '%s', '%s', '%s')", $edit['nid'], $edit['pid'], $edit['uid'], $edit['subject'], $edit['comment'], $edit['comment_format'], ip_address(), $edit['timestamp'], $edit['status'], $thread, $edit['name'], $edit['mail'], $edit['homepage']); $edit['cid'] = db_last_insert_id('comments', 'cid'); // Tell the other modules a new comment has been submitted. comment_invoke_comment($edit, 'insert'); @@ -1341,17 +1341,14 @@ function comment_form(&$form_state, $edi $default = ''; } - $form['comment_filter']['comment'] = array( + $form['comment'] = array( '#type' => 'textarea', '#title' => t('Comment'), '#rows' => 15, '#default_value' => $default, + '#input_format' => isset($edit['format']) ? $edit['format'] : FILTER_FORMAT_DEFAULT, '#required' => TRUE, ); - if (!isset($edit['format'])) { - $edit['format'] = FILTER_FORMAT_DEFAULT; - } - $form['comment_filter']['format'] = filter_form($edit['format']); $form['cid'] = array( '#type' => 'value', @@ -1431,6 +1428,7 @@ function comment_form_add_preview($form, if (!form_get_errors()) { _comment_form_submit($edit); $comment = (object)$edit; + $comment->format = $comment->comment_format; // Attach the user and time information. if (!empty($edit['author'])) { @@ -1523,7 +1521,7 @@ function _comment_form_submit(&$comment_ // 2) Strip out all HTML tags // 3) Convert entities back to plain-text. // Note: format is checked by check_markup(). - $comment_values['subject'] = trim(truncate_utf8(decode_entities(strip_tags(check_markup($comment_values['comment'], $comment_values['format']))), 29, TRUE)); + $comment_values['subject'] = trim(truncate_utf8(decode_entities(strip_tags(check_markup($comment_values['comment'], $comment_values['comment_format']))), 29, TRUE)); // Edge cases where the comment body is populated only by HTML tags will // require a default subject. if ($comment_values['subject'] == '') { @@ -1541,7 +1539,6 @@ function comment_form_submit($form, &$fo $node = node_load($form_state['values']['nid']); $page = comment_new_page_count($node->comment_count, 1, $node); $form_state['redirect'] = array('node/' . $node->nid, $page, "comment-$cid"); - return; } } Index: modules/node/node.module =================================================================== RCS file: /cvs/drupal/drupal/modules/node/node.module,v retrieving revision 1.977 diff -u -p -r1.977 node.module --- modules/node/node.module 17 Sep 2008 20:37:32 -0000 1.977 +++ modules/node/node.module 27 Sep 2008 04:06:37 -0000 @@ -858,6 +858,7 @@ function node_submit($node) { // module-provided 'teaser' form item). if (!isset($node->teaser)) { if (isset($node->body)) { + $node->format = (!empty($node->body_format) ? $node->body_format : FILTER_FORMAT_DEFAULT); $node->teaser = node_teaser($node->body, isset($node->format) ? $node->format : NULL); // Chop off the teaser from the body if needed. The teaser_include // property might not be set (eg. in Blog API postings), so only act on @@ -938,7 +939,6 @@ function node_save(&$node) { $node->changed = REQUEST_TIME; $node->timestamp = REQUEST_TIME; - $node->format = isset($node->format) ? $node->format : FILTER_FORMAT_DEFAULT; $update_node = TRUE; // Generate the node table query and the node_revisions table query. Index: modules/node/node.pages.inc =================================================================== RCS file: /cvs/drupal/drupal/modules/node/node.pages.inc,v retrieving revision 1.37 diff -u -p -r1.37 node.pages.inc --- modules/node/node.pages.inc 19 Sep 2008 07:39:00 -0000 1.37 +++ modules/node/node.pages.inc 27 Sep 2008 04:03:42 -0000 @@ -296,10 +296,9 @@ function node_body_field(&$node, $label, '#default_value' => $include ? $node->body : ($node->teaser . $node->body), '#rows' => 20, '#required' => ($word_count > 0), + '#input_format' => isset($node->format) ? $node->format : FILTER_FORMAT_DEFAULT, ); - $form['format'] = filter_form($node->format); - return $form; } Index: modules/system/system.module =================================================================== RCS file: /cvs/drupal/drupal/modules/system/system.module,v retrieving revision 1.623 diff -u -p -r1.623 system.module --- modules/system/system.module 20 Sep 2008 03:49:24 -0000 1.623 +++ modules/system/system.module 27 Sep 2008 04:03:42 -0000 @@ -219,7 +219,7 @@ function system_elements() { '#size' => 60, '#maxlength' => 128, '#autocomplete_path' => FALSE, - '#process' => array('form_process_ahah'), + '#process' => array('form_process_input_format', 'form_process_ahah'), ); $type['password'] = array( @@ -239,7 +239,7 @@ function system_elements() { '#cols' => 60, '#rows' => 5, '#resizable' => TRUE, - '#process' => array('form_process_ahah'), + '#process' => array('form_process_input_format', 'form_process_ahah'), ); $type['radios'] = array(