diff options
Diffstat (limited to 'modules')
-rw-r--r-- | modules/aggregator/aggregator.module | 38 | ||||
-rw-r--r-- | modules/block/block.module | 21 | ||||
-rw-r--r-- | modules/book/book.module | 17 | ||||
-rw-r--r-- | modules/color/color.module | 4 | ||||
-rw-r--r-- | modules/comment/comment.module | 69 | ||||
-rw-r--r-- | modules/contact/contact.module | 24 | ||||
-rw-r--r-- | modules/dblog/dblog.module | 4 | ||||
-rw-r--r-- | modules/filter/filter.module | 18 | ||||
-rw-r--r-- | modules/forum/forum.module | 36 | ||||
-rw-r--r-- | modules/menu/menu.module | 21 | ||||
-rw-r--r-- | modules/node/content_types.inc | 15 | ||||
-rw-r--r-- | modules/node/node.module | 117 | ||||
-rw-r--r-- | modules/path/path.module | 16 | ||||
-rw-r--r-- | modules/poll/poll.module | 25 | ||||
-rw-r--r-- | modules/profile/profile.module | 12 | ||||
-rw-r--r-- | modules/search/search.module | 25 | ||||
-rw-r--r-- | modules/system/system.install | 56 | ||||
-rw-r--r-- | modules/system/system.module | 169 | ||||
-rw-r--r-- | modules/taxonomy/taxonomy.module | 23 | ||||
-rw-r--r-- | modules/throttle/throttle.module | 2 | ||||
-rw-r--r-- | modules/upload/upload.module | 18 | ||||
-rw-r--r-- | modules/user/user.module | 158 |
22 files changed, 508 insertions, 380 deletions
diff --git a/modules/aggregator/aggregator.module b/modules/aggregator/aggregator.module index 10b69c1b5..f0074b584 100644 --- a/modules/aggregator/aggregator.module +++ b/modules/aggregator/aggregator.module @@ -357,7 +357,7 @@ function aggregator_form_category($edit = array('title' => '', 'description' => /** * Validate aggregator_form_feed form submissions. */ -function aggregator_form_category_validate($form_id, $form_values) { +function aggregator_form_category_validate($form_values, $form, &$form_state) { if ($form_values['op'] == t('Submit')) { // Check for duplicate titles if (isset($form_values['cid'])) { @@ -376,7 +376,7 @@ function aggregator_form_category_validate($form_id, $form_values) { * Process aggregator_form_category form submissions. * @todo Add delete confirmation dialog. */ -function aggregator_form_category_submit($form_id, $form_values) { +function aggregator_form_category_submit($form_values, $form, &$form_state) { if ($form_values['op'] == t('Delete')) { $title = $form_values['title']; // Unset the title: @@ -388,20 +388,24 @@ function aggregator_form_category_submit($form_id, $form_values) { if (isset($form_values['title'])) { drupal_set_message(t('The category %category has been updated.', array('%category' => $form_values['title']))); if (arg(0) == 'admin') { - return 'admin/content/aggregator/'; + $form_state['redirect'] = 'admin/content/aggregator/'; + return; } else { - return 'aggregator/categories/'. $form_values['cid']; + $form_state['redirect'] = 'aggregator/categories/'. $form_values['cid']; + return; } } else { watchdog('aggregator', 'Category %category deleted.', array('%category' => $title)); drupal_set_message(t('The category %category has been deleted.', array('%category' => $title))); if (arg(0) == 'admin') { - return 'admin/content/aggregator/'; + $form_state['redirect'] = 'admin/content/aggregator/'; + return; } else { - return 'aggregator/categories/'; + $form_state['redirect'] = 'aggregator/categories/'; + return; } } } @@ -488,7 +492,7 @@ function aggregator_form_feed($edit = array('refresh' => 900, 'title' => '', 'ur /** * Validate aggregator_form_feed form submissions. */ -function aggregator_form_feed_validate($form_id, $form_values) { +function aggregator_form_feed_validate($form_values, $form, &$form_state) { if ($form_values['op'] == t('Submit')) { // Check for duplicate titles if (isset($form_values['fid'])) { @@ -512,7 +516,7 @@ function aggregator_form_feed_validate($form_id, $form_values) { * Process aggregator_form_feed form submissions. * @todo Add delete confirmation dialog. */ -function aggregator_form_feed_submit($form_id, $form_values) { +function aggregator_form_feed_submit($form_values, $form, &$form_state) { if ($form_values['op'] == t('Delete')) { $title = $form_values['title']; // Unset the title: @@ -524,20 +528,24 @@ function aggregator_form_feed_submit($form_id, $form_values) { if (isset($form_values['title'])) { drupal_set_message(t('The feed %feed has been updated.', array('%feed' => $form_values['title']))); if (arg(0) == 'admin') { - return 'admin/content/aggregator/'; + $form_state['redirect'] = 'admin/content/aggregator/'; + return; } else { - return 'aggregator/sources/'. $form_values['fid']; + $form_state['redirect'] = 'aggregator/sources/'. $form_values['fid']; + return; } } else { watchdog('aggregator', 'Feed %feed deleted.', array('%feed' => $title)); drupal_set_message(t('The feed %feed has been deleted.', array('%feed' => $title))); if (arg(0) == 'admin') { - return 'admin/content/aggregator/'; + $form_state['redirect'] = 'admin/content/aggregator/'; + return; } else { - return 'aggregator/sources/'; + $form_state['redirect'] = 'aggregator/sources/'; + return; } } } @@ -1076,8 +1084,8 @@ function aggregator_page_category() { } function aggregator_page_list($sql, $header, $categorize) { - $form['#submit']['aggregator_page_list_submit'] = array(); - $form['#validate']['aggregator_page_list_validate'] = array(); + $form['#submit'][] = 'aggregator_page_list_submit'; + $form['#validate'][] = 'aggregator_page_list_validate'; $form['#theme'] = 'aggregator_page_list'; $form['header'] = array('#value' => $header); $result = pager_query($sql, 20); @@ -1162,7 +1170,7 @@ function aggregator_page_list_validate($form_id, &$form) { } } -function aggregator_page_list_submit($form_id, $form_values) { +function aggregator_page_list_submit($form_values, $form, &$form_state) { foreach ($form_values['categories'] as $iid => $selection) { db_query('DELETE FROM {aggregator_category_item} WHERE iid = %d', $iid); foreach ($selection as $cid) { diff --git a/modules/block/block.module b/modules/block/block.module index 04b2d2e24..0091ad8e2 100644 --- a/modules/block/block.module +++ b/modules/block/block.module @@ -292,7 +292,7 @@ function _block_compare($a, $b) { /** * Process main block administration form submission. */ -function block_admin_display_submit($form_id, $form_values) { +function block_admin_display_submit($form_values, $form, &$form_state) { foreach ($form_values as $block) { $block['status'] = $block['region'] != BLOCK_REGION_NONE; $block['region'] = $block['status'] ? $block['region'] : ''; @@ -498,7 +498,7 @@ function block_admin_configure($module = NULL, $delta = 0) { return $form; } -function block_admin_configure_validate($form_id, $form_values) { +function block_admin_configure_validate($form_values, $form, &$form_state) { if ($form_values['module'] == 'block') { if (empty($form_values['info']) || db_num_rows(db_query("SELECT bid FROM {boxes} WHERE bid != %d AND info = '%s'", $form_values['delta'], $form_values['info']))) { form_set_error('info', t('Please ensure that each block description is unique.')); @@ -506,7 +506,7 @@ function block_admin_configure_validate($form_id, $form_values) { } } -function block_admin_configure_submit($form_id, $form_values) { +function block_admin_configure_submit($form_values, $form, &$form_state) { if (!form_get_errors()) { db_query("UPDATE {blocks} SET visibility = %d, pages = '%s', custom = %d, title = '%s' WHERE module = '%s' AND delta = '%s'", $form_values['visibility'], trim($form_values['pages']), $form_values['custom'], $form_values['title'], $form_values['module'], $form_values['delta']); db_query("DELETE FROM {blocks_roles} WHERE module = '%s' AND delta = '%s'", $form_values['module'], $form_values['delta']); @@ -516,7 +516,8 @@ function block_admin_configure_submit($form_id, $form_values) { module_invoke($form_values['module'], 'block', 'save', $form_values['delta'], $form_values); drupal_set_message(t('The block configuration has been saved.')); cache_clear_all(); - return 'admin/build/block'; + $form_state['redirect'] = 'admin/build/block'; + return; } } @@ -527,7 +528,7 @@ function block_add_block_form() { return block_admin_configure('block', NULL); } -function block_add_block_form_validate($form_id, $form_values) { +function block_add_block_form_validate($form_values, $form, &$form_state) { if (empty($form_values['info']) || db_num_rows(db_query("SELECT info FROM {boxes} WHERE info = '%s'", $form_values['info']))) { form_set_error('info', t('Please ensure that each block description is unique.')); } @@ -536,7 +537,7 @@ function block_add_block_form_validate($form_id, $form_values) { /** * Save the new custom block. */ -function block_add_block_form_submit($form_id, $form_values) { +function block_add_block_form_submit($form_values, $form, &$form_state) { $delta = db_next_id('{boxes}_bid'); foreach (list_themes() as $key => $theme) { @@ -554,7 +555,8 @@ function block_add_block_form_submit($form_id, $form_values) { drupal_set_message(t('The block has been created.')); cache_clear_all(); - return 'admin/build/block'; + $form_state['redirect'] = 'admin/build/block'; + return; } /** @@ -571,12 +573,13 @@ function block_box_delete($bid = 0) { /** * Deletion of custom blocks. */ -function block_box_delete_submit($form_id, $form_values) { +function block_box_delete_submit($form_values, $form, &$form_state) { db_query('DELETE FROM {boxes} WHERE bid = %d', $form_values['bid']); db_query("DELETE FROM {blocks} WHERE module = 'block' AND delta = %d", $form_values['bid']); drupal_set_message(t('The block %name has been removed.', array('%name' => $form_values['info']))); cache_clear_all(); - return 'admin/build/block'; + $form_state['redirect'] = 'admin/build/block'; + return; }; /** diff --git a/modules/book/book.module b/modules/book/book.module index 7c0399c95..1d272cbb3 100644 --- a/modules/book/book.module +++ b/modules/book/book.module @@ -199,12 +199,12 @@ function book_insert($node) { /** * Implementation of hook_submit(). */ -function book_submit(&$node) { +function book_submit(&$form_values) { global $user; // Set default values for non-administrators. if (!user_access('administer nodes')) { - $node->revision = 1; - $node->uid = $user->uid; + $form_values['revision'] = 1; + $form_values['uid'] = $user->uid; } } @@ -298,7 +298,7 @@ function book_outline($node) { /** * Handles book outline form submissions. */ -function book_outline_submit($form_id, $form_values) { +function book_outline_submit($form_values, $form, &$form_state) { $op = $form_values['op']; $node = node_load($form_values['nid']); @@ -318,7 +318,8 @@ function book_outline_submit($form_id, $form_values) { drupal_set_message(t('The post has been removed from the book.')); break; } - return "node/$node->nid"; + $form_state['redirect'] = "node/$node->nid"; + return; } /** @@ -924,13 +925,13 @@ function book_admin_orphan() { else { $form['error'] = array('#value' => '<p>'. t('There are no orphan pages.') .'</p>'); } - $form['#submit']['book_admin_edit_submit'] = array(); - $form['#validate']['book_admin_edit_validate'] = array(); + $form['#submit'][] = 'book_admin_edit_submit'; + $form['#validate'][] = 'book_admin_edit_validate'; $form['#theme'] = 'book_admin_edit'; return $form; } -function book_admin_edit_submit($form_id, $form_values) { +function book_admin_edit_submit($form_values, $form, &$form_state) { foreach ($form_values['table'] as $row) { $node = node_load($row['nid']); diff --git a/modules/color/color.module b/modules/color/color.module index 04bbb8ff6..1ea6c2a1b 100644 --- a/modules/color/color.module +++ b/modules/color/color.module @@ -26,7 +26,7 @@ function color_form_alter(&$form, $form_id) { '#theme' => 'color_scheme_form', ); $form['color'] += color_scheme_form(arg(4)); - $form['#submit']['color_scheme_form_submit'] = array(); + $form['#submit'][] = 'color_scheme_form_submit'; } // Use the generated screenshot in the theme list @@ -183,7 +183,7 @@ function theme_color_scheme_form($form) { /** * Submit handler for color change form. */ -function color_scheme_form_submit($form_id, $values) { +function color_scheme_form_submit($values, $form, &$form_state) { // Get theme coloring info if (!isset($values['info'])) { return; diff --git a/modules/comment/comment.module b/modules/comment/comment.module index df097ac19..91b02a43b 100644 --- a/modules/comment/comment.module +++ b/modules/comment/comment.module @@ -1106,23 +1106,8 @@ function comment_delete($cid = NULL) { $output = ''; - // We'll only delete if the user has confirmed the - // deletion using the form in our else clause below. - if (is_object($comment) && is_numeric($comment->cid) && $_POST['confirm']) { - drupal_set_message(t('The comment and all its replies have been deleted.')); - - // Delete comment and its replies. - _comment_delete_thread($comment); - - _comment_update_node_statistics($comment->nid); - - // Clear the cache so an anonymous user sees that his comment was deleted. - cache_clear_all(); - - drupal_goto("node/$comment->nid"); - } - else if (is_object($comment) && is_numeric($comment->cid)) { - $output = drupal_get_form('comment_confirm_delete', $comment->subject, $comment->nid); + if (is_object($comment) && is_numeric($comment->cid)) { + $output = drupal_get_form('comment_confirm_delete', $comment); } else { drupal_set_message(t('The comment no longer exists.')); @@ -1131,14 +1116,34 @@ function comment_delete($cid = NULL) { return $output; } -function comment_confirm_delete($subject, $nid) { +function comment_confirm_delete($comment) { + $form = array(); + $form['#comment'] = $comment; return confirm_form( - array(), - t('Are you sure you want to delete the comment %title?', array('%title' => $subject)), - 'node/'. $nid, + $form, + t('Are you sure you want to delete the comment %title?', array('%title' => $comment->subject)), + 'node/'. $comment->nid, t('Any replies to this comment will be lost. This action cannot be undone.'), t('Delete'), - t('Cancel')); + t('Cancel'), + 'comment_confirm_delete'); +} + +function comment_confirm_delete_submit($form_values, $form, &$form_state) { + drupal_set_message(t('The comment and all its replies have been deleted.')); + + $comment = $form['#comment']; + + // Delete comment and its replies. + _comment_delete_thread($comment); + + _comment_update_node_statistics($comment->nid); + + // Clear the cache so an anonymous user sees that his comment was deleted. + cache_clear_all(); + + $form_state['redirect'] = "node/$comment->nid"; + return; } /** @@ -1224,7 +1229,7 @@ function comment_admin_overview($type = 'new', $arg) { /** * We can't execute any 'Update options' if no comments were selected. */ -function comment_admin_overview_validate($form_id, $form_values) { +function comment_admin_overview_validate($form_values, $form, &$form_state) { $form_values['comments'] = array_diff($form_values['comments'], array(0)); if (count($form_values['comments']) == 0) { form_set_error('', t('Please select one or more comments to perform the update on.')); @@ -1236,7 +1241,7 @@ function comment_admin_overview_validate($form_id, $form_values) { * Execute the chosen 'Update option' on the selected comments, such as * publishing, unpublishing or deleting. */ -function comment_admin_overview_submit($form_id, $form_values) { +function comment_admin_overview_submit($form_values, $form, &$form_state) { $operations = comment_operations(); if ($operations[$form_values['operation']][1]) { // extract the appropriate database query operation @@ -1321,7 +1326,7 @@ function comment_multiple_delete_confirm() { /** * Perform the actual comment deletion. */ -function comment_multiple_delete_confirm_submit($form_id, $form_values) { +function comment_multiple_delete_confirm_submit($form_values, $form, &$form_state) { if ($form_values['confirm']) { foreach ($form_values['comments'] as $cid => $value) { $comment = _comment_load($cid); @@ -1448,7 +1453,6 @@ function comment_validate($edit) { ** Generate the basic commenting form, for appending to a node or display on a separate page. ** This is rendered by theme_comment_form. */ - function comment_form($edit, $title = NULL) { global $user; @@ -1619,7 +1623,7 @@ function comment_form_box($edit, $title = NULL) { return theme('box', $title, drupal_get_form('comment_form', $edit, $title)); } -function comment_form_add_preview($form, $edit) { +function comment_form_add_preview($form, $edit, &$form_state) { global $user; drupal_set_title(t('Preview comment')); @@ -1630,7 +1634,7 @@ function comment_form_add_preview($form, $edit) { // request forgeries (CSRF) and setting arbitrary values for fields such as // the input format. Preview the comment only when form validation does not // set any errors. - drupal_validate_form($form['form_id']['#value'], $form); + drupal_validate_form($form['form_id']['#value'], $form, $form_state); if (!form_get_errors()) { $comment = (object)_comment_form_submit($edit); @@ -1676,7 +1680,7 @@ function comment_form_add_preview($form, $edit) { return $form; } -function comment_form_validate($form_id, $form_values) { +function comment_form_validate($form_values, $form, &$form_state) { comment_validate($form_values); } @@ -1709,10 +1713,11 @@ function _comment_form_submit($form_values) { return $form_values; } -function comment_form_submit($form_id, $form_values) { +function comment_form_submit(&$form_values, $form, &$form_state) { $form_values = _comment_form_submit($form_values); if ($cid = comment_save($form_values)) { - return array('node/'. $form_values['nid'], NULL, "comment-$cid"); + $form_state['redirect'] = array('node/'. $form_values['nid'], NULL, "comment-$cid"); + return; } } @@ -1795,7 +1800,7 @@ function theme_comment_controls($form) { return theme('box', t('Comment viewing options'), $output); } -function comment_controls_submit($form_id, $form_values) { +function comment_controls_submit($form_values, $form, &$form_state) { global $user; $mode = $form_values['mode']; diff --git a/modules/contact/contact.module b/modules/contact/contact.module index e8cb12851..950930995 100644 --- a/modules/contact/contact.module +++ b/modules/contact/contact.module @@ -209,7 +209,7 @@ function contact_admin_edit($cid = NULL) { /** * Validate the contact category edit page form submission. */ -function contact_admin_edit_validate($form_id, $form_values) { +function contact_admin_edit_validate($form_values, $form, &$form_state) { if (empty($form_values['category'])) { form_set_error('category', t('You must enter a category.')); } @@ -229,7 +229,7 @@ function contact_admin_edit_validate($form_id, $form_values) { /** * Process the contact category edit page form submission. */ -function contact_admin_edit_submit($form_id, $form_values) { +function contact_admin_edit_submit($form_values, $form, &$form_state) { if ($form_values['selected']) { // Unselect all other contact categories. db_query('UPDATE {contact} SET selected = 0'); @@ -252,7 +252,8 @@ function contact_admin_edit_submit($form_id, $form_values) { watchdog('mail', 'Contact form: category %category updated.', array('%category' => $form_values['category']), WATCHDOG_NOTICE, l(t('view'), 'admin/build/contact')); } - return 'admin/build/contact'; + $form_state['redirect'] = 'admin/build/contact'; + return; } /** @@ -275,12 +276,13 @@ function contact_admin_delete($cid = NULL) { /** * Process category delete form submission. */ -function contact_admin_delete_submit($form_id, $form_values) { +function contact_admin_delete_submit($form_values, $form, &$form_state) { db_query("DELETE FROM {contact} WHERE cid = %d", arg(4)); drupal_set_message(t('Category %category has been deleted.', array('%category' => $form_values['category']))); watchdog('mail', 'Contact form: category %category deleted.', array('%category' => $form_values['category']), WATCHDOG_NOTICE); - return 'admin/build/contact'; + $form_state['redirect'] = 'admin/build/contact'; + return; } function contact_admin_settings() { @@ -357,7 +359,7 @@ function contact_mail_user($recipient) { /** * Process the personal contact page form submission. */ -function contact_mail_user_submit($form_id, $form_values) { +function contact_mail_user_submit($form_values, $form, &$form_state) { global $user; $account = user_load(array('uid' => arg(1), 'status' => 1)); @@ -399,7 +401,8 @@ function contact_mail_user_submit($form_id, $form_values) { drupal_set_message(t('The message has been sent.')); // Jump to the user's profile page: - return "user/$account->uid"; + $form_state['redirect'] = "user/$account->uid"; + return; } /** @@ -493,7 +496,7 @@ function contact_mail_page() { /** * Validate the site-wide contact page form submission. */ -function contact_mail_page_validate($form_id, $form_values) { +function contact_mail_page_validate($form_values, $form, &$form_state) { if (!$form_values['cid']) { form_set_error('category', t('You must select a valid category.')); } @@ -505,7 +508,7 @@ function contact_mail_page_validate($form_id, $form_values) { /** * Process the site-wide contact page form submission. */ -function contact_mail_page_submit($form_id, $form_values) { +function contact_mail_page_submit($form_values, $form, &$form_state) { // E-mail address of the sender: as the form field is a text field, // all instances of \r and \n have been automatically stripped from it. @@ -550,6 +553,7 @@ function contact_mail_page_submit($form_id, $form_values) { drupal_set_message(t('Your message has been sent.')); // Jump to home page rather than back to contact page to avoid contradictory messages if flood control has been activated. - return ''; + $form_state['redirect'] = ''; + return; } diff --git a/modules/dblog/dblog.module b/modules/dblog/dblog.module index 120752464..c812f0383 100644 --- a/modules/dblog/dblog.module +++ b/modules/dblog/dblog.module @@ -369,7 +369,7 @@ function theme_dblog_filters($form) { return $output; } -function dblog_filter_form_validate($form_id, $form_values) { +function dblog_filter_form_validate($form_values, $form, &$form_state) { if ($form_values['op'] == t('Filter') && empty($form_values['type']) && empty($form_values['severity'])) { form_set_error('type', t('You must select something to filter by.')); } @@ -378,7 +378,7 @@ function dblog_filter_form_validate($form_id, $form_values) { /** * Process result from dblog administration filter form. */ -function dblog_filter_form_submit($form_id, $form_values) { +function dblog_filter_form_submit($form_id, $form_values, &$form_state) { $op = $form_values['op']; $filters = dblog_filters(); switch ($op) { diff --git a/modules/filter/filter.module b/modules/filter/filter.module index 3c0a82117..d891ab2a6 100644 --- a/modules/filter/filter.module +++ b/modules/filter/filter.module @@ -296,7 +296,7 @@ function filter_admin_overview() { return $form; } -function filter_admin_overview_submit($form_id, $form_values) { +function filter_admin_overview_submit($form_values, $form, &$form_state) { // Process form submission to set the default format if (is_numeric($form_values['default'])) { drupal_set_message(t('Default format updated.')); @@ -352,7 +352,7 @@ function filter_admin_delete() { /** * Process filter delete form submission. */ -function filter_admin_delete_submit($form_id, $form_values) { +function filter_admin_delete_submit($form_values, $form, &$form_state) { db_query("DELETE FROM {filter_formats} WHERE format = %d", $form_values['format']); db_query("DELETE FROM {filters} WHERE format = %d", $form_values['format']); @@ -365,7 +365,8 @@ function filter_admin_delete_submit($form_id, $form_values) { cache_clear_all($form_values['format'] .':', 'cache_filter', TRUE); drupal_set_message(t('Deleted input format %format.', array('%format' => $form_values['name']))); - return 'admin/settings/filters'; + $form_state['redirect'] = 'admin/settings/filters'; + return; } /** @@ -441,7 +442,7 @@ function filter_admin_format_form($format = NULL) { /** * Validate filter format form submissions. */ -function filter_admin_format_form_validate($form_id, $form_values) { +function filter_admin_format_form_validate($form_values, $form, &$form_state) { if (!isset($form_values['format'])) { $name = trim($form_values['name']); $result = db_fetch_object(db_query("SELECT format FROM {filter_formats} WHERE name='%s'", $name)); @@ -454,7 +455,7 @@ function filter_admin_format_form_validate($form_id, $form_values) { /** * Process filter format form submissions. */ -function filter_admin_format_form_submit($form_id, $form_values) { +function filter_admin_format_form_submit($form_values, $form, &$form_state) { $format = isset($form_values['format']) ? $form_values['format'] : NULL; $current = filter_list_format($format); $name = trim($form_values['name']); @@ -506,7 +507,8 @@ function filter_admin_format_form_submit($form_id, $form_values) { if (!empty($new)) { $return .= '/'. $format; } - return $return; + $form_state['redirect'] = $return; + return; } /** @@ -549,7 +551,7 @@ function theme_filter_admin_order($form) { /** * Process filter order configuration form submission. */ -function filter_admin_order_submit($form_id, $form_values) { +function filter_admin_order_submit($form_values, $form, &$form_state) { foreach ($form_values['weights'] as $id => $weight) { list($module, $delta) = explode('/', $id); db_query("UPDATE {filters} SET weight = %d WHERE format = %d AND module = '%s' AND delta = %d", $weight, $form_values['format'], $module, $delta); @@ -784,7 +786,7 @@ function filter_form($value = FILTER_FORMAT_DEFAULT, $weight = NULL, $parents = '#collapsible' => TRUE, '#collapsed' => TRUE, '#weight' => $weight, - '#validate' => array('filter_form_validate' => array()), + '#element_validate' => array('filter_form_validate'), ); // Multiple formats available: display radio buttons with tips. foreach ($formats as $format) { diff --git a/modules/forum/forum.module b/modules/forum/forum.module index fad2a05e4..6d865df52 100644 --- a/modules/forum/forum.module +++ b/modules/forum/forum.module @@ -348,11 +348,11 @@ function forum_view(&$node, $teaser = FALSE, $page = FALSE) { * Check in particular that only a "leaf" term in the associated taxonomy * vocabulary is selected, not a "container" term. */ -function forum_submit(&$node) { +function forum_submit(&$form_values) { // Make sure all fields are set properly: - $node->icon = !empty($node->icon) ? $node->icon : ''; + $form_values['icon'] = $form_values['icon'] ? $form_values['icon'] : ''; - if ($node->taxonomy) { + if ($form_values['taxonomy']) { // Get the forum terms from the (cached) tree $tree = taxonomy_get_tree(_forum_get_vid()); if ($tree) { @@ -360,16 +360,16 @@ function forum_submit(&$node) { $forum_terms[] = $term->tid; } } - foreach ($node->taxonomy as $term) { + foreach ($form_values['taxonomy'] as $term) { if (in_array($term, $forum_terms)) { - $node->tid = $term; + $form_values['tid'] = $term; } } - $old_tid = db_result(db_query_range("SELECT tid FROM {forum} WHERE nid = %d ORDER BY vid DESC", $node->nid, 0, 1)); + $old_tid = db_result(db_query_range("SELECT tid FROM {forum} WHERE nid = %d ORDER BY vid DESC", $form_values['nid'], 0, 1)); if ($old_tid) { - if (($node->tid != $old_tid) && $node->shadow) { + if (($form_values['tid'] != $old_tid) && $form_values['shadow']) { // A shadow copy needs to be created. Retain new term and add old term. - $node->taxonomy[] = $old_tid; + $form_values['taxonomy'][] = $old_tid; } } } @@ -499,8 +499,8 @@ function forum_form_container($edit = array()) { $form['delete'] = array('#type' => 'submit', '#value' => t('Delete')); $form['tid'] = array('#type' => 'value', '#value' => $edit['tid']); } - $form['#submit']['forum_form_submit'] = array(); - $form['#validate']['forum_form_validate'] = array(); + $form['#submit'][] = 'forum_form_submit'; + $form['#validate'][] = 'forum_form_validate'; $form['#theme'] = 'forum_form'; return $form; @@ -558,8 +558,8 @@ function forum_form_forum($edit = array()) { $form['delete'] = array('#type' => 'submit', '#value' => t('Delete')); $form['tid'] = array('#type' => 'hidden', '#value' => $edit['tid']); } - $form['#submit']['forum_form_submit'] = array(); - $form['#validate']['forum_form_validate'] = array(); + $form['#submit'][] = 'forum_form_submit'; + $form['#validate'][] = 'forum_form_validate'; $form['#theme'] = 'forum_form'; return $form; @@ -568,8 +568,8 @@ function forum_form_forum($edit = array()) { /** * Process forum form and container form submissions. */ -function forum_form_submit($form_id, $form_values) { - if ($form_id == 'forum_form_container') { +function forum_form_submit($form_values, $form, &$form_state) { + if ($form['form_id'] == 'forum_form_container') { $container = TRUE; $type = t('forum container'); } @@ -592,7 +592,8 @@ function forum_form_submit($form_id, $form_values) { drupal_set_message(t('The @type %term has been updated.', array('%term' => $form_values['name'], '@type' => $type))); break; } - return 'admin/content/forum'; + $form_state['redirect'] = 'admin/content/forum'; + return; } /** @@ -612,12 +613,13 @@ function forum_confirm_delete($tid) { /** * Implementation of forms api _submit call. Deletes a forum after confirmation. */ -function forum_confirm_delete_submit($form_id, $form_values) { +function forum_confirm_delete_submit($form_values, $form, &$form_state) { taxonomy_del_term($form_values['tid']); drupal_set_message(t('The forum %term and all sub-forums and associated posts have been deleted.', array('%term' => $form_values['name']))); watchdog('content', 'forum: deleted %term and all its sub-forums and associated posts.', array('%term' => $form_values['name'])); - return 'admin/content/forum'; + $form_state['redirect'] = 'admin/content/forum'; + return; } /** diff --git a/modules/menu/menu.module b/modules/menu/menu.module index a24f717c9..2dfda5984 100644 --- a/modules/menu/menu.module +++ b/modules/menu/menu.module @@ -321,7 +321,7 @@ function menu_edit_item_form($type, $mid = 0) { return $form; } -function menu_edit_item_form_validate($form_id, $form_values) { +function menu_edit_item_form_validate($form_values, $form, &$form_state) { if (isset($form_values['path'])) { $path = $form_values['path']; // Skip external links. @@ -341,9 +341,10 @@ function menu_edit_item_form_validate($form_id, $form_values) { /** * Process menu and menu item add/edit form submissions. */ -function menu_edit_item_form_submit($form_id, $form_values) { +function menu_edit_item_form_submit($form_values, $form, &$form_state) { menu_edit_item_save($form_values); - return 'admin/build/menu'; + $form_state['redirect'] = 'admin/build/menu'; + return; } /** @@ -461,8 +462,8 @@ function menu_edit_menu_form($type, $mid = 0) { $form['type'] = array('#type' => 'value', '#value' => $item['type']); $form['submit'] = array('#type' => 'submit', '#value' => t('Submit')); // Reuse the submit function of menu_edit_item_form. - $form['#submit']['menu_edit_item_form_submit'] = array(); - $form['#validate']['menu_edit_item_form_validate'] = array(); + $form['#submit'][] = 'menu_edit_item_form_submit'; + $form['#validate'][] = 'menu_edit_item_form_validate'; $form['#theme'] = 'menu_edit_item_form'; return $form; @@ -494,7 +495,7 @@ function menu_item_delete_form($mid) { /** * Process menu delete form submissions. */ -function menu_item_delete_form_submit($form_id, $form_values) { +function menu_item_delete_form_submit($form_values, $form, &$form_state) { menu_delete_item($form_values['path']); $t_args = array('%title' => $form_values['title']); @@ -507,7 +508,8 @@ function menu_item_delete_form_submit($form_id, $form_values) { watchdog('menu', 'Deleted menu item %title.', $t_args, WATCHDOG_NOTICE); } - return 'admin/build/menu'; + $form_state['redirect'] = 'admin/build/menu'; + return; } /** @@ -526,11 +528,12 @@ function menu_reset_item($mid) { /** * Process menu reset item form submissions. */ -function menu_reset_item_submit($form_id, $form_values) { +function menu_reset_item_submit($form_values, $form, &$form_state) { menu_delete_item($form_values['mid']); drupal_set_message(t('The menu item was reset to its default settings.')); - return 'admin/build/menu'; + $form_state['redirect'] = 'admin/build/menu'; + return; } /** diff --git a/modules/node/content_types.inc b/modules/node/content_types.inc index 18fb2115f..ae6ba1e06 100644 --- a/modules/node/content_types.inc +++ b/modules/node/content_types.inc @@ -216,7 +216,7 @@ function node_type_form($type = NULL) { /** * Implementation of hook_form_validate(). */ -function node_type_form_validate($form_id, $form_values) { +function node_type_form_validate($form_values, $form, &$form_state) { $type = new stdClass(); $type->type = trim($form_values['type']); $type->name = trim($form_values['name']); @@ -252,7 +252,7 @@ function node_type_form_validate($form_id, $form_values) { /** * Implementation of hook_form_submit(). */ -function node_type_form_submit($form_id, $form_values) { +function node_type_form_submit($form_values, $form, &$form_state) { $op = isset($form_values['op']) ? $form_values['op'] : ''; $type = new stdClass(); @@ -282,7 +282,8 @@ function node_type_form_submit($form_id, $form_values) { node_type_reset($type); } elseif ($op == t('Delete content type')) { - return 'admin/content/types/'. str_replace('_', '-', $type->old_type) .'/delete'; + $form_state['redirect'] = 'admin/content/types/'. str_replace('_', '-', $type->old_type) .'/delete'; + return; } $status = node_type_save($type); @@ -336,7 +337,8 @@ function node_type_form_submit($form_id, $form_values) { watchdog('node', 'Added content type %name.', $t_args, WATCHDOG_NOTICE, l(t('view'), 'admin/content/types')); } - return 'admin/content/types'; + $form_state['redirect'] = 'admin/content/types'; + return; } /** @@ -396,7 +398,7 @@ function node_type_delete_confirm($type) { /** * Process content type delete confirm submissions. */ -function node_type_delete_confirm_submit($form_id, $form_values) { +function node_type_delete_confirm_submit($form_values, $form, &$form_state) { node_type_delete($form_values['type']); $t_args = array('%name' => $form_values['name']); @@ -406,5 +408,6 @@ function node_type_delete_confirm_submit($form_id, $form_values) { node_types_rebuild(); menu_rebuild(); - return 'admin/content/types'; + $form_state['redirect'] = 'admin/content/types'; + return; } diff --git a/modules/node/node.module b/modules/node/node.module index 624dd502a..c70f3aa0b 100644 --- a/modules/node/node.module +++ b/modules/node/node.module @@ -173,7 +173,7 @@ function node_mark($nid, $timestamp) { /** * See if the user used JS to submit a teaser. */ -function node_teaser_js(&$form, $form_values) { +function node_teaser_js(&$form, $form_values, &$form_state) { // Glue the teaser to the body. if (isset($form['#post']['teaser_js'])) { if (trim($form_values['teaser_js'])) { @@ -185,7 +185,7 @@ function node_teaser_js(&$form, $form_values) { $body = '<!--break-->'. $form_values['body']; } // Pass value onto preview/submit - form_set_value($form['body'], $body); + form_set_value($form['body'], $body, $form_state); // Pass value back onto form $form['body']['#value'] = $body; } @@ -1066,7 +1066,7 @@ function node_configure() { /** * Form validate callback. */ -function node_configure_validate($form_id, $form_values) { +function node_configure_validate($form_values, $form, &$form_state) { if ($form_values['op'] == t('Rebuild permissions')) { drupal_goto('admin/content/node-settings/rebuild'); } @@ -1083,10 +1083,11 @@ function node_configure_rebuild_confirm() { /** * Handler for wipe confirmation */ -function node_configure_rebuild_confirm_submit($form_id, &$form) { +function node_configure_rebuild_confirm_submit(&$form, $form, &$form_state) { node_access_rebuild(); drupal_set_message(t('The node access table has been rebuilt.')); - return 'admin/content/node-settings'; + $form_state['redirect'] = 'admin/content/node-settings'; + return; } /** @@ -1514,7 +1515,7 @@ function theme_node_filters($form) { /** * Process result from node administration filter form. */ -function node_filter_form_submit($form_id, $form_values) { +function node_filter_form_submit($form_values, $form, &$form_state) { $filters = node_filters(); switch ($form_values['op']) { case t('Filter'): @@ -1542,7 +1543,7 @@ function node_filter_form_submit($form_id, $form_values) { /** * Submit the node administration update form. */ -function node_admin_nodes_submit($form_id, $form_values) { +function node_admin_nodes_submit($form_values, $form, &$form_state) { $operations = module_invoke_all('node_operations'); $operation = $operations[$form_values['operation']]; // Filter out unchecked nodes @@ -1562,7 +1563,7 @@ function node_admin_nodes_submit($form_id, $form_values) { } } -function node_admin_nodes_validate($form_id, $form_values) { +function node_admin_nodes_validate($form_values, $form, &$form_state) { $nodes = array_filter($form_values['nodes']); if (count($nodes) == 0) { form_set_error('', t('No items selected.')); @@ -1683,14 +1684,15 @@ function node_multiple_delete_confirm() { t('Delete all'), t('Cancel')); } -function node_multiple_delete_confirm_submit($form_id, $form_values) { +function node_multiple_delete_confirm_submit($form_values, $form, &$form_state) { if ($form_values['confirm']) { foreach ($form_values['nodes'] as $nid => $value) { node_delete($nid); } drupal_set_message(t('The items have been deleted.')); } - return 'admin/content/node'; + $form_state['redirect'] = 'admin/content/node'; + return; } /** @@ -1956,10 +1958,6 @@ function node_submit($node) { $node->created = $node->date ? strtotime($node->date) : NULL; } - // Do node-type-specific validation checks. - node_invoke($node, 'submit'); - node_invoke_nodeapi($node, 'submit'); - $node->validated = TRUE; return $node; @@ -2003,7 +2001,7 @@ function node_validate($node, $form = array()) { node_invoke_nodeapi($node, 'validate', $form); } -function node_form_validate($form_id, $form_values, $form) { +function node_form_validate($form_values, $form, &$form_state) { node_validate($form_values, $form); } @@ -2025,9 +2023,15 @@ function node_object_prepare(&$node) { /** * Generate the node add/edit form array. */ -function node_form($node, $form_values = NULL) { +function node_form($node, $form_state = NULL) { global $user; + if (isset($form_state['node'])) { + $node = $form_state['node'] + (array)$node; + } + if (isset($form_state['node_preview'])) { + $form['#prefix'] = $form_state['node_preview']; + } $node = (object)$node; foreach (array('body', 'title', 'format') as $key) { if (!isset($node->$key)) { @@ -2050,7 +2054,7 @@ function node_form($node, $form_values = NULL) { // Changed must be sent to the client, for later overwrite error checking. $form['changed'] = array('#type' => 'hidden', '#default_value' => isset($node->changed) ? $node->changed : NULL); // Get the node-specific bits. - if ($extra = node_invoke($node, 'form', $form_values)) { + if ($extra = node_invoke($node, 'form', $form_state)) { $form = array_merge_recursive($form, $extra); } if (!isset($form['title']['#weight'])) { @@ -2118,46 +2122,43 @@ function node_form($node, $form_values = NULL) { } // Add the buttons. - $form['preview'] = array('#type' => 'button', '#value' => t('Preview'), '#weight' => 40); - $form['submit'] = array('#type' => 'submit', '#value' => t('Submit'), '#weight' => 45); + $form['preview'] = array( + '#type' => 'submit', + '#value' => t('Preview'), + '#weight' => 40, + '#submit' => array('node_form_build_preview'), + ); + $form['submit'] = array( + '#type' => 'submit', + '#value' => t('Submit'), + '#weight' => 45, + '#submit' => array('node_form_submit'), + ); if (!empty($node->nid) && node_access('delete', $node)) { $form['delete'] = array('#type' => 'button', '#value' => t('Delete'), '#weight' => 50); } - $form['#after_build'] = array('node_form_add_preview'); - $form['#submit']['node_form_submit'] = array(); - $form['#validate']['node_form_validate'] = array(); + $form['#validate'][] = 'node_form_validate'; $form['#theme'] = 'node_form'; return $form; } -function node_form_add_preview($form) { - global $form_values; - - $op = isset($form_values['op']) ? $form_values['op'] : ''; - if ($op == t('Preview')) { - // Invoke full validation for the form, to protect against cross site - // request forgeries (CSRF) and setting arbitrary values for fields such as - // the input format. Preview the node only when form validation does not - // set any errors. - drupal_validate_form($form['form_id']['#value'], $form); - if (!form_get_errors()) { - // Because the node preview may display a form, we must render it - // outside the node submission form tags using the #prefix property - // (i.e. to prevent illegally nested forms). - // If the node form already has a #prefix, we must preserve it. - // In this case, we put the preview before the #prefix so we keep - // the #prefix as "close" to the rest of the form as possible, - // for example, to keep a <div> only around the form, not the - // preview. We pass the global $form_values here to preserve - // changes made during form validation. - $preview = node_preview((object)$form_values); - $form['#prefix'] = isset($form['#prefix']) ? $preview . $form['#prefix'] : $preview; - } - } - if (variable_get('node_preview', 0) && (form_get_errors() || $op != t('Preview'))) { - unset($form['submit']); - } - return $form; +function node_form_build_preview($form_values, $form, &$form_state) { + // We do not want to execute button level handlers, we want the form level + // handlers to go in and change the submitted values. + unset($form_state['submit_handlers']); + form_execute_handlers('submit', $form, $form_state); + // Because the node preview may display a form, we must render it + // outside the node submission form tags using the #prefix property + // (i.e. to prevent illegally nested forms). + // If the node form already has a #prefix, we must preserve it. + // In this case, we put the preview before the #prefix so we keep + // the #prefix as "close" to the rest of the form as possible, + // for example, to keep a <div> only around the form, not the + // preview. We pass the global $form_values here to preserve + // changes made during form validation. + $form_state['node_preview'] = node_preview((object)$form_state['values']); + $form_state['rebuild'] = TRUE; + $form_state['node'] = $form_state['values']; } function theme_node_form($form) { @@ -2289,7 +2290,7 @@ function node_preview($node) { */ function theme_node_preview($node) { $output = '<div class="preview">'; - if ($node->teaser && $node->teaser != $node->body) { + if (!empty($node->teaser) && !empty($node->body) && $node->teaser != $node->body) { drupal_set_message(t('The trimmed version of your post shows what your post looks like when promoted to the main page or when exported for syndication.<span class="no-js"> You can insert the delimiter "<!--break-->" (without the quotes) to fine-tune where your post gets split.</span>')); $output .= '<h3>'. t('Preview trimmed version') .'</h3>'; $output .= node_view(drupal_clone($node), 1, FALSE, 0); @@ -2308,7 +2309,7 @@ function theme_node_log_message($log) { return '<div class="log"><div class="title">'. t('Log') .':</div>'. $log .'</div>'; } -function node_form_submit($form_id, $form_values) { +function node_form_submit($form_values, $form, &$form_state) { global $user; // Fix up the node when required: @@ -2327,10 +2328,7 @@ function node_form_submit($form_id, $form_values) { } if ($node->nid) { if (node_access('view', $node)) { - return 'node/'. $node->nid; - } - else { - return ''; + $form_state['redirect'] = 'node/'. $node->nid; } } // it is very unlikely we get here @@ -2448,6 +2446,7 @@ function node_page_default() { $default_message = t('<h1 class="title">Welcome to your new Drupal website!</h1><p>Please follow these steps to set up and start using your website:</p>'); $default_message .= '<ol>'; + $default_message .= '<li>'. t('<strong>Configure your website</strong> Once logged in, visit the <a href="@admin">administration section</a>, where you can <a href="@config">customize and configure</a> all aspects of your website.', array('@admin' => url('admin'), '@config' => url('admin/settings'))) .'</li>'; $default_message .= '<li>'. t('<strong>Enable additional functionality</strong> Next, visit the <a href="@modules">module list</a> and enable features which suit your specific needs. You can find additional modules in the <a href="@download_modules">Drupal modules download section</a>.', array('@modules' => url('admin/build/modules'), '@download_modules' => 'http://drupal.org/project/modules')) .'</li>'; $default_message .= '<li>'. t('<strong>Customize your website design</strong> To change the "look and feel" of your website, visit the <a href="@themes">themes section</a>. You may choose from one of the included themes or download additional themes from the <a href="@download_themes">Drupal themes download section</a>.', array('@themes' => url('admin/build/themes'), '@download_themes' => 'http://drupal.org/project/themes')) .'</li>'; @@ -2606,14 +2605,14 @@ function node_form_alter(&$form, $form_id) { '#suffix' => '</div>', ); - $form['#validate']['node_search_validate'] = array(); + $form['#validate'][] = 'node_search_validate'; } } /** * Form API callback for the search form. Registered in node_form_alter(). */ -function node_search_validate($form_id, $form_values, $form) { +function node_search_validate($form_values, $form, &$form_state) { // Initialise using any existing basic search keywords. $keys = $form_values['processed_keys']; @@ -2643,7 +2642,7 @@ function node_search_validate($form_id, $form_values, $form) { $keys .= ' "'. str_replace('"', ' ', $form_values['phrase']) .'"'; } if (!empty($keys)) { - form_set_value($form['basic']['inline']['processed_keys'], trim($keys)); + form_set_value($form['basic']['inline']['processed_keys'], trim($keys), $form_state); } } diff --git a/modules/path/path.module b/modules/path/path.module index 0312c941e..d6beffcf1 100644 --- a/modules/path/path.module +++ b/modules/path/path.module @@ -105,10 +105,11 @@ function path_admin_delete_confirm($pid) { /** * Execute URL alias deletion **/ -function path_admin_delete_confirm_submit($form_id, $form_values) { +function path_admin_delete_confirm_submit($form_values, $form, &$form_state) { if ($form_values['confirm']) { path_admin_delete($form_values['pid']); - return 'admin/build/path'; + $form_state['redirect'] = 'admin/build/path'; + return; } } @@ -178,8 +179,8 @@ function path_set_alias($path = NULL, $alias = NULL, $pid = NULL, $language = '' * Return a form for editing or creating an individual URL alias. */ function path_form($edit = array('src' => '', 'dst' => '', 'language' => '', 'pid' => NULL)) { - $form['#submit']['path_form_submit'] = array(); - $form['#validate']['path_form_validate'] = array(); + $form['#submit'][] = 'path_form_submit'; + $form['#validate'][] = 'path_form_validate'; $form['#alias'] = $edit; $form['src'] = array( @@ -369,7 +370,7 @@ function path_load($pid) { /** * Verify that a new URL alias is valid */ -function path_form_validate($form_id, $form_values) { +function path_form_validate($form_values, $form, &$form_state) { $src = $form_values['src']; $dst = $form_values['dst']; $pid = isset($form_values['pid']) ? $form_values['pid'] : 0; @@ -384,12 +385,13 @@ function path_form_validate($form_id, $form_values) { /** * Save a new URL alias to the database. */ -function path_form_submit($form_id, $form_values) { +function path_form_submit($form_values, $form, &$form_state) { // Language is only set if locale module is enabled path_set_alias($form_values['src'], $form_values['dst'], isset($form_values['pid']) ? $form_values['pid'] : 0, isset($form_values['language']) ? $form_values['language'] : ''); drupal_set_message(t('The alias has been saved.')); - return 'admin/build/path'; + $form_state['redirect'] = 'admin/build/path'; + return; } /** diff --git a/modules/poll/poll.module b/modules/poll/poll.module index afe3c59fd..8fef97946 100644 --- a/modules/poll/poll.module +++ b/modules/poll/poll.module @@ -99,10 +99,14 @@ function poll_delete($node) { /** * Implementation of hook_submit(). */ -function poll_submit(&$node) { +function poll_node_form_submit(&$form_values, $form, &$form_state) { // Renumber fields - $node->choice = array_values($node->choice); - $node->teaser = poll_teaser($node); + $form_values['choice'] = array_values($form_values['choice']); + $form_values['teaser'] = poll_teaser((object)$form_values); + $form_state['choices'] = $form_values['choices']; + if ($form_values['morechoices']) { + $form_state['choices'] *= 2; + } } /** @@ -132,7 +136,7 @@ function poll_validate($node) { /** * Implementation of hook_form(). */ -function poll_form($node, $form_values = NULL) { +function poll_form($node, $form_state = NULL) { $admin = user_access('administer nodes'); $type = node_get_types('type', $node); $form['title'] = array( @@ -143,11 +147,8 @@ function poll_form($node, $form_values = NULL) { '#weight' => -1 ); - if (isset($form_values)) { - $choices = $form_values['choices']; - if ($form_values['morechoices']) { - $choices *= 2; - } + if (isset($form_state['choices'])) { + $choices = $form_state['choices']; } else { $choices = max(2, empty($node->choice) ? 5 : count($node->choice)); @@ -174,7 +175,7 @@ function poll_form($node, $form_values = NULL) { '#type' => 'checkbox', '#parents' => array('morechoices'), '#title' => t('Need more choices'), - '#value' => 0, + '#default_value' => 0, '#description' => t("If the amount of boxes above isn't enough, check this box and click the Preview button below to add some more."), '#weight' => 1, ); @@ -183,14 +184,14 @@ function poll_form($node, $form_values = NULL) { $form['choice'][$a]['chtext'] = array( '#type' => 'textfield', '#title' => t('Choice @n', array('@n' => ($a + 1))), - '#default_value' => isset($node->choice) ? $node->choice[$a]['chtext'] : '', + '#default_value' => isset($node->choice[$a]) ? $node->choice[$a]['chtext'] : '', ); if ($admin) { $form['choice'][$a]['chvotes'] = array( '#type' => 'textfield', '#title' => t('Votes for choice @n', array('@n' => ($a + 1))), - '#default_value' => isset($node->choice) ? (int)$node->choice[$a]['chvotes'] : 0, + '#default_value' => isset($node->choice[$a]) ? (int)$node->choice[$a]['chvotes'] : 0, '#size' => 5, '#maxlength' => 7 ); } diff --git a/modules/profile/profile.module b/modules/profile/profile.module index 93fccc078..af6d23d84 100644 --- a/modules/profile/profile.module +++ b/modules/profile/profile.module @@ -331,7 +331,7 @@ Unless you know what you are doing, it is highly recommended that you prefix the /** * Validate profile_field_form submissions. */ -function profile_field_form_validate($form_id, $form_values) { +function profile_field_form_validate($form_values, $form, &$form_state) { // Validate the 'field name': if (preg_match('/[^a-zA-Z0-9_-]/', $form_values['name'])) { form_set_error('name', t('The specified form name contains one or more illegal characters. Spaces or any other special characters except dash (-) and underscore (_) are not allowed.')); @@ -367,7 +367,7 @@ function profile_field_form_validate($form_id, $form_values) { /** * Process profile_field_form submissions. */ -function profile_field_form_submit($form_id, $form_values) { +function profile_field_form_submit($form_values, $form, &$form_state) { if (!isset($form_values['fid'])) { db_query("INSERT INTO {profile_fields} (title, name, explanation, category, type, weight, required, register, visibility, autocomplete, options, page) VALUES ('%s', '%s', '%s', '%s', '%s', %d, %d, %d, %d, %d, '%s', '%s')", $form_values['title'], $form_values['name'], $form_values['explanation'], $form_values['category'], $form_values['type'], $form_values['weight'], $form_values['required'], $form_values['register'], $form_values['visibility'], $form_values['autocomplete'], $form_values['options'], $form_values['page']); @@ -382,7 +382,8 @@ function profile_field_form_submit($form_id, $form_values) { cache_clear_all(); menu_rebuild(); - return 'admin/user/profile'; + $form_state['redirect'] = 'admin/user/profile'; + return; } /** @@ -406,7 +407,7 @@ function profile_field_delete($fid) { /** * Process a field delete form submission. */ -function profile_field_delete_submit($form_id, $form_values) { +function profile_field_delete_submit($form_values, $form, &$form_state) { db_query('DELETE FROM {profile_fields} WHERE fid = %d', $form_values['fid']); db_query('DELETE FROM {profile_values} WHERE fid = %d', $form_values['fid']); @@ -415,7 +416,8 @@ function profile_field_delete_submit($form_id, $form_values) { drupal_set_message(t('The field %field has been deleted.', array('%field' => $form_values['title']))); watchdog('profile', 'Profile field %field deleted.', array('%field' => $form_values['title']), WATCHDOG_NOTICE, l(t('view'), 'admin/user/profile')); - return 'admin/user/profile'; + $form_state['redirect'] = 'admin/user/profile'; + return; } /** diff --git a/modules/search/search.module b/modules/search/search.module index fde62393a..ebe2ac7f1 100644 --- a/modules/search/search.module +++ b/modules/search/search.module @@ -207,7 +207,7 @@ function _search_menu($name) { /** * Validate callback. */ -function search_admin_settings_validate($form_id, $form_values) { +function search_admin_settings_validate($form_values, $form, &$form_state) { if ($form_values['op'] == t('Re-index site')) { drupal_goto('admin/settings/search/wipe'); } @@ -268,11 +268,12 @@ function search_wipe_confirm() { /** * Handler for wipe confirmation */ -function search_wipe_confirm_submit($form_id, &$form) { +function search_wipe_confirm_submit(&$form, $form, &$form_state) { if ($form['confirm']) { search_wipe(); drupal_set_message(t('The index will be rebuilt.')); - return 'admin/settings/search'; + $form_state['redirect'] = 'admin/settings/search'; + return; } } @@ -1043,14 +1044,14 @@ function search_form($action = '', $keys = '', $type = NULL, $prompt = NULL) { * search_form_validate() is used solely to set the 'processed_keys' form * value for the basic search form. */ -function search_form_validate($form_id, $form_values, $form) { - form_set_value($form['basic']['inline']['processed_keys'], trim($form_values['keys'])); +function search_form_validate($form_values, $form, &$form_state) { + form_set_value($form['basic']['inline']['processed_keys'], trim($form_values['keys'], $form_state)); } /** * Process a search form submission. */ -function search_form_submit($form_id, $form_values) { +function search_form_submit($form_values, $form, &$form_state) { $keys = $form_values['processed_keys']; if ($keys == '') { form_set_error('keys', t('Please enter some keywords.')); @@ -1058,7 +1059,8 @@ function search_form_submit($form_id, $form_values) { } $type = $form_values['module'] ? $form_values['module'] : 'node'; - return 'search/'. $type .'/'. $keys; + $form_state['redirect'] = 'search/'. $type .'/'. $keys; + return; } /** @@ -1076,8 +1078,8 @@ function search_box($form_id) { // Always go to the search page since the search form is not guaranteed to be // on every page. $form['#action'] = url('search/node'); - $form['#submit']['search_box_form_submit'] = array(); - $form['#validate']['search_box_form_validate'] = array(); + $form['#submit'][] = 'search_box_form_submit'; + $form['#validate'][] = 'search_box_form_validate'; $form['#theme'] = 'search_box_form'; return $form; @@ -1086,8 +1088,9 @@ function search_box($form_id) { /** * Process a block search form submission. */ -function search_box_form_submit($form_id, $form_values) { - return 'search/node/'. trim($form_values[$form_id .'_keys']); +function search_box_form_submit($form_values, $form, &$form_state) { + $form_state['redirect'] = 'search/node/'. trim($form_values[$form_id .'_keys']); + return; } /** diff --git a/modules/system/system.install b/modules/system/system.install index 4a33350be..2578bb8b8 100644 --- a/modules/system/system.install +++ b/modules/system/system.install @@ -252,6 +252,16 @@ function system_install() { PRIMARY KEY (cid), INDEX expire (expire) ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); + db_query("CREATE TABLE {cache_form} ( + cid varchar(255) BINARY NOT NULL default '', + data longblob, + expire int NOT NULL default '0', + created int NOT NULL default '0', + headers text, + serialized int(1) NOT NULL default '0', + PRIMARY KEY (cid), + INDEX expire (expire) + ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); db_query("CREATE TABLE {comments} ( cid int NOT NULL auto_increment, @@ -734,9 +744,19 @@ function system_install() { serialized smallint NOT NULL default '0', PRIMARY KEY (cid) )"); + db_query("CREATE TABLE {cache_form} ( + cid varchar(255) NOT NULL default '', + data bytea, + expire int NOT NULL default '0', + created int NOT NULL default '0', + headers text, + serialized int(1) NOT NULL default '0', + PRIMARY KEY (cid) + )"); db_query("CREATE INDEX {cache}_expire_idx ON {cache} (expire)"); db_query("CREATE INDEX {cache_filter}_expire_idx ON {cache_filter} (expire)"); db_query("CREATE INDEX {cache_page}_expire_idx ON {cache_page} (expire)"); + db_query("CREATE INDEX {cache_form}_expire_idx ON {cache_form} (expire)"); db_query("CREATE TABLE {comments} ( cid serial, @@ -3885,6 +3905,42 @@ function system_update_6014() { return array(); } +/** + * Add the form cache table. + */ +function system_update_6015() { + $ret = array(); + + switch ($GLOBALS['db_type']) { + case 'pgsql': + $ret[] = update_sql("CREATE TABLE {cache_form} ( + cid varchar(255) NOT NULL default '', + data bytea, + expire int NOT NULL default '0', + created int NOT NULL default '0', + headers text, + serialized int(1) NOT NULL default '0', + PRIMARY KEY (cid) + )"); + $ret[] = update_sql("CREATE INDEX {cache_form}_expire_idx ON {cache_form} (expire)"); + break; + case 'mysql': + case 'mysqli': + $ret[] = update_sql("CREATE TABLE {cache_form} ( + cid varchar(255) NOT NULL default '', + data longblob, + expire int NOT NULL default '0', + created int NOT NULL default '0', + headers text, + serialized int(1) NOT NULL default '0', + PRIMARY KEY (cid), + INDEX expire (expire) + ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); + break; + } + + return $ret; +} /** * @} End of "defgroup updates-5.x-to-6.x" diff --git a/modules/system/system.module b/modules/system/system.module index 51478a383..bca53c764 100644 --- a/modules/system/system.module +++ b/modules/system/system.module @@ -99,14 +99,14 @@ function system_elements() { $type['button'] = array('#input' => TRUE, '#name' => 'op', '#button_type' => 'submit', '#executes_submit_callback' => FALSE); $type['textfield'] = array('#input' => TRUE, '#size' => 60, '#maxlength' => 128, '#autocomplete_path' => FALSE); $type['password'] = array('#input' => TRUE, '#size' => 60, '#maxlength' => 128); - $type['password_confirm'] = array('#input' => TRUE, '#process' => array('expand_password_confirm' => array())); + $type['password_confirm'] = array('#input' => TRUE, '#process' => array('expand_password_confirm')); $type['textarea'] = array('#input' => TRUE, '#cols' => 60, '#rows' => 5, '#resizable' => TRUE); - $type['radios'] = array('#input' => TRUE, '#process' => array('expand_radios' => array())); + $type['radios'] = array('#input' => TRUE, '#process' => array('expand_radios')); $type['radio'] = array('#input' => TRUE, '#default_value' => NULL); - $type['checkboxes'] = array('#input' => TRUE, '#process' => array('expand_checkboxes' => array()), '#tree' => TRUE); + $type['checkboxes'] = array('#input' => TRUE, '#process' => array('expand_checkboxes'), '#tree' => TRUE); $type['select'] = array('#input' => TRUE, '#size' => 0, '#multiple' => FALSE); - $type['weight'] = array('#input' => TRUE, '#delta' => 10, '#default_value' => 0, '#process' => array('process_weight' => array())); - $type['date'] = array('#input' => TRUE, '#process' => array('expand_date' => array()), '#validate' => array('date_validate' => array())); + $type['weight'] = array('#input' => TRUE, '#delta' => 10, '#default_value' => 0, '#process' => array('process_weight')); + $type['date'] = array('#input' => TRUE, '#process' => array('expand_date' => array()), '#element_validate' => array('date_validate')); $type['file'] = array('#input' => TRUE, '#size' => 60); // Form structure @@ -474,13 +474,13 @@ function system_admin_theme_settings() { // In order to give it our own submit, we have to give it the default submit // too because the presence of a #submit will prevent the default #submit // from being used. Also we want ours first. - $form['#submit']['system_admin_theme_submit'] = array(); - $form['#submit']['system_settings_form_submit'] = array(); + $form['#submit'][] = 'system_admin_theme_submit'; + $form['#submit'][] = 'system_settings_form_submit'; return system_settings_form($form); } -function system_admin_theme_submit($form_id, $form_values) { +function system_admin_theme_submit($form_values, $form, &$form_state) { // If we're changing themes, make sure the theme has its blocks initialized. if ($form_values['admin_theme'] != variable_get('admin_theme', '0')) { $result = db_query("SELECT status FROM {blocks} WHERE theme = '%s'", $form_values['admin_theme']); @@ -749,8 +749,8 @@ function system_performance_settings() { '#description' => t("Some Drupal modules include their own CSS files. When these modules are enabled, each module's CSS file adds an additional HTTP request to the page, which can increase the load time of each page. These HTTP requests can also slightly increase server load. It is recommended to only turn this option on when your site is in production, as it can interfere with theme development. This option is disabled if you have not set up your files directory, or if your download method is set to private."), ); - $form['#submit']['system_settings_form_submit'] = array(); - $form['#submit']['drupal_clear_css_cache'] = array(); + $form['#submit'][] = 'system_settings_form_submit'; + $form['#submit'][] = 'drupal_clear_css_cache'; return system_settings_form($form); } @@ -1168,13 +1168,13 @@ function system_settings_form($form) { if (!empty($_POST) && form_get_errors()) { drupal_set_message(t('The settings have not been saved because of the errors.'), 'error'); } - $form['#submit']['system_settings_form_submit'] = array(); - $form['#validate']['system_settings_form_validate'] = array(); + $form['#submit'][] = 'system_settings_form_submit'; + $form['#validate'][] = 'system_settings_form_validate'; $form['#theme'] = 'system_settings_form'; return $form; } -function system_theme_settings_submit($form_id, $form_values) { +function system_theme_settings_submit($form_values, $form, &$form_state) { $op = isset($_POST['op']) ? $_POST['op'] : ''; $key = $form_values['var']; @@ -1200,7 +1200,7 @@ function system_theme_settings_submit($form_id, $form_values) { * add an array_filter value to your form. * */ -function system_settings_form_submit($form_id, $form_values) { +function system_settings_form_submit($form_values, $form, &$form_state) { $op = isset($form_values['op']) ? $form_values['op'] : ''; // Exclude unnecessary elements. @@ -1305,7 +1305,7 @@ function theme_system_themes_form($form) { } -function system_themes_form_submit($form_id, $form_values) { +function system_themes_form_submit($form_values, $form, &$form_state) { db_query("UPDATE {system} SET status = 0 WHERE type = 'theme'"); @@ -1336,7 +1336,8 @@ function system_themes_form_submit($form_id, $form_values) { list_themes(TRUE); menu_rebuild(); drupal_set_message(t('The configuration options have been saved.')); - return 'admin/build/themes'; + $form_state['redirect'] = 'admin/build/themes'; + return; } /** @@ -1354,12 +1355,13 @@ function system_themes_form_submit($form_id, $form_values) { * @return * The form array. */ -function system_modules($form_values = NULL) { +function system_modules($form_state = array()) { // Get current list of modules. $files = module_rebuild_cache(); - if ($confirm_form = system_modules_confirm_form($files, $form_values)) { - return $confirm_form; + if (!empty($form_state['storage'])) { + return system_modules_confirm_form($files, $form_state['storage']); } + $dependencies = array(); // Store module list for validation callback. $form['validation_modules'] = array('#type' => 'value', '#value' => $files); @@ -1449,9 +1451,10 @@ function system_modules($form_values = NULL) { '#default_value' => $status, '#options' => $options, '#process' => array( - 'expand_checkboxes' => array(), - 'system_modules_disable' => array($disabled), + 'expand_checkboxes', + 'system_modules_disable', ), + '#disabled_modules' => $disabled, ); // Handle throttle checkboxes, including overriding the @@ -1462,9 +1465,10 @@ function system_modules($form_values = NULL) { '#default_value' => $throttle, '#options' => $options, '#process' => array( - 'expand_checkboxes' => array(), - 'system_modules_disable' => array(array_merge($modules_required, array('throttle'))), + 'expand_checkboxes', + 'system_modules_disable', ), + '#disabled_modules' => array_merge($modules_required, array('throttle')), ); } @@ -1472,7 +1476,6 @@ function system_modules($form_values = NULL) { '#type' => 'submit', '#value' => t('Save configuration'), ); - $form['#multistep'] = TRUE; $form['#action'] = url('admin/build/modules/list/confirm'); return $form; @@ -1481,43 +1484,33 @@ function system_modules($form_values = NULL) { /** * Form process callback function to disable check boxes. */ -function system_modules_disable($form, $edit, $disabled) { - foreach ($disabled as $key) { +function system_modules_disable($form, $edit) { + foreach ($form['#disabled_modules'] as $key) { $form[$key]['#attributes']['disabled'] = 'disabled'; } return $form; } -function system_modules_confirm_form($modules, $form_values = array()) { +function system_modules_confirm_form($modules, $dependencies) { $form = array(); $items = array(); - // Check values for submitted dependency errors. - if ($dependencies = system_module_build_dependencies($modules, $form_values)) { - // preserve the already switched on modules - foreach ($modules as $name => $module) { - if ($module->status) { - $form['status'][$name] = array('#type' => 'hidden', '#value' => 1); - } - } - - $form['validation_modules'] = array('#type' => 'value', '#value' => $modules); - $form['status']['#tree'] = TRUE; - foreach ($dependencies as $name => $missing_dependencies) { - $form['status'][$name] = array('#type' => 'hidden', '#value' => 1); - foreach ($missing_dependencies as $k => $dependency) { - $form['status'][$dependency] = array('#type' => 'hidden', '#value' => 1); - $info = $modules[$dependency]->info; - $missing_dependencies[$k] = $info['name'] ? $info['name'] : drupal_ucfirst($dependency); - } - $t_argument = array( - '@module' => $modules[$name]->info['name'], - '@dependencies' => implode(', ', $missing_dependencies), - ); - $items[] = format_plural(count($missing_dependencies), 'You must enable the @dependencies module to install @module.', 'You must enable the @dependencies modules to install @module.', $t_argument); - } - $form['text'] = array('#value' => theme('item_list', $items)); + $form['validation_modules'] = array('#type' => 'value', '#value' => $modules); + $form['status']['#tree'] = TRUE; + foreach ($dependencies as $name => $missing_dependencies) { + $form['status'][$name] = array('#type' => 'hidden', '#value' => 1); + foreach ($missing_dependencies as $k => $dependency) { + $form['status'][$dependency] = array('#type' => 'hidden', '#value' => 1); + $info = $modules[$dependency]->info; + $missing_dependencies[$k] = $info['name'] ? $info['name'] : drupal_ucfirst($dependency); + } + $t_argument = array( + '@module' => $modules[$name]->info['name'], + '@dependencies' => implode(', ', $missing_dependencies), + ); + $items[] = format_plural(count($missing_dependencies), 'You must enable the @dependencies module to install @module.', 'You must enable the @dependencies modules to install @module.', $t_argument); } + $form['text'] = array('#value' => theme('item_list', $items)); if ($form) { // Set some default form values @@ -1557,22 +1550,28 @@ function system_module_build_dependencies($modules, $form_values) { /** * Submit callback; handles modules form submission. */ -function system_modules_submit($form_id, $form_values) { +function system_modules_submit($form_values, $form, &$form_state) { include_once './includes/install.inc'; $new_modules = array(); - // Merge in disabled active modules since they should be enabled. - // They don't appear because disabled checkboxes are not submitted - // by browsers. - $form_values['status'] = array_merge($form_values['status'], $form_values['disabled_modules']); - - // Check values for dependency that we can't install. - if ($dependencies = system_module_build_dependencies($form_values['validation_modules'], $form_values)) { - // These are the modules that depend on existing modules. - foreach (array_keys($dependencies) as $name) { - $form_values['status'][$name] = 0; + // If we are coming from the confirm form... + if (!isset($form_state['storage'])) { + // Merge in disabled active modules since they should be enabled. + // They don't appear because disabled checkboxes are not submitted + // by browsers. + $form_values['status'] = array_merge($form_values['status'], $form_values['disabled_modules']); + + // Check values for dependency that we can't install. + if ($dependencies = system_module_build_dependencies($form_values['validation_modules'], $form_values)) { + // These are the modules that depend on existing modules. + foreach (array_keys($dependencies) as $name) { + $form_values['status'][$name] = 0; + } } } + else { + $dependencies = NULL; + } $enable_modules = array(); $disable_modules = array(); @@ -1624,12 +1623,16 @@ function system_modules_submit($form_id, $form_values) { // If there where unmet dependencies and they haven't confirmed don't redirect. if ($dependencies && !isset($form_values['confirm'])) { - return FALSE; + $form_state['storage'] = $dependencies; + return; } drupal_clear_css_cache(); - return 'admin/build/modules'; + // Unset storage to indicate this form cycle is over. + unset($form_state['storage']); + $form_state['redirect'] = 'admin/build/modules'; + return; } /** @@ -1700,12 +1703,12 @@ function theme_system_modules($form) { * @return * A form array representing the currently disabled modules. */ -function system_modules_uninstall($form_values = NULL) { +function system_modules_uninstall($form_state = NULL) { // Make sure the install API is available. include_once './includes/install.inc'; // Display the confirm form if any modules have been submitted. - if ($confirm_form = system_modules_uninstall_confirm_form($form_values)) { + if (isset($form_state) && $confirm_form = system_modules_uninstall_confirm_form($form_state['storage'])) { return $confirm_form; } @@ -1735,10 +1738,9 @@ function system_modules_uninstall($form_values = NULL) { '#options' => $options, ); $form['buttons']['submit'] = array( - '#type' => 'button', + '#type' => 'submit', '#value' => t('Uninstall'), ); - $form['#multistep'] = TRUE; $form['#action'] = url('admin/build/modules/uninstall/confirm'); } else { @@ -1756,14 +1758,14 @@ function system_modules_uninstall($form_values = NULL) { * @return * A form array representing modules to confirm. */ -function system_modules_uninstall_confirm_form($form_values) { +function system_modules_uninstall_confirm_form($storage) { // Nothing to build. - if (!isset($form_values)) { + if (!isset($storage)) { return; } // Construct the hidden form elements and list items. - foreach (array_filter($form_values['uninstall']) as $module => $value) { + foreach (array_filter($storage['uninstall']) as $module => $value) { $info = drupal_parse_info_file(dirname(drupal_get_filename('module', $module)) .'/'. $module .'.info'); $uninstall[] = $info['name']; $form['uninstall'][$module] = array('#type' => 'hidden', @@ -1773,8 +1775,8 @@ function system_modules_uninstall_confirm_form($form_values) { // Display a confirm form if modules have been selected. if (isset($uninstall)) { + $form['#confirmed'] = TRUE; $form['uninstall']['#tree'] = TRUE; - $form['#multistep'] = TRUE; $form['modules'] = array('#value' => '<p>'. t('The following modules will be completely uninstalled from your site, and <em>all data from these modules will be lost</em>!') .'</p>'. theme('item_list', $uninstall)); $form = confirm_form( $form, @@ -1836,7 +1838,7 @@ function theme_system_modules_uninstall($form) { * @param * $form_values Submitted form values. */ -function system_modules_uninstall_validate($form_id, $form_values) { +function system_modules_uninstall_validate($form_values, $form, &$form_state) { // Form submitted, but no modules selected. if (!count(array_filter($form_values['uninstall']))) { drupal_set_message(t('No modules selected.'), 'error'); @@ -1852,16 +1854,23 @@ function system_modules_uninstall_validate($form_id, $form_values) { * @param * $form_values Submitted form values. */ -function system_modules_uninstall_submit($form_id, $form_values) { +function system_modules_uninstall_submit($form_values, $form, &$form_state) { // Make sure the install API is available. include_once './includes/install.inc'; - // Call the uninstall routine for each selected module. - foreach (array_filter($form_values['uninstall']) as $module => $value) { - drupal_uninstall_module($module); + if (!empty($form['#confirmed'])) { + // Call the uninstall routine for each selected module. + foreach (array_filter($form_values['uninstall']) as $module => $value) { + drupal_uninstall_module($module); + } + drupal_set_message(t('The selected modules have been uninstalled.')); + + unset($form_state['storage']); + $form_state['redirect'] = 'admin/build/modules/uninstall'; + } + else { + $form_state['storage'] = $form_values; } - drupal_set_message(t('The selected modules have been uninstalled.')); - drupal_goto('admin/build/modules/uninstall'); } /** diff --git a/modules/taxonomy/taxonomy.module b/modules/taxonomy/taxonomy.module index e6d4ce518..c008e301e 100644 --- a/modules/taxonomy/taxonomy.module +++ b/modules/taxonomy/taxonomy.module @@ -304,7 +304,7 @@ function taxonomy_form_vocabulary($edit = array()) { /** * Accept the form submission for a vocabulary and save the results. */ -function taxonomy_form_vocabulary_submit($form_id, $form_values) { +function taxonomy_form_vocabulary_submit($form_values, $form, &$form_state) { // Fix up the nodes array to remove unchecked nodes. $form_values['nodes'] = array_filter($form_values['nodes']); switch (taxonomy_save_vocabulary($form_values)) { @@ -318,7 +318,9 @@ function taxonomy_form_vocabulary_submit($form_id, $form_values) { break; } - return 'admin/content/taxonomy'; + $form_state['vid'] = $form_values['vid']; + $form_state['redirect'] = 'admin/content/taxonomy'; + return; } function taxonomy_save_vocabulary(&$edit) { @@ -391,11 +393,12 @@ function taxonomy_vocabulary_confirm_delete($vid) { t('Cancel')); } -function taxonomy_vocabulary_confirm_delete_submit($form_id, $form_values) { +function taxonomy_vocabulary_confirm_delete_submit($form_values, $form, &$form_state) { $status = taxonomy_del_vocabulary($form_values['vid']); drupal_set_message(t('Deleted vocabulary %name.', array('%name' => $form_values['name']))); watchdog('taxonomy', 'Deleted vocabulary %name.', array('%name' => $form_values['name']), WATCHDOG_NOTICE); - return 'admin/content/taxonomy'; + $form_state['redirect'] = 'admin/content/taxonomy'; + return; } function taxonomy_form_term($vocabulary, $edit = array()) { @@ -476,7 +479,7 @@ function taxonomy_form_term($vocabulary, $edit = array()) { /** * Accept the form submission for a taxonomy term and save the result. */ -function taxonomy_form_term_submit($form_id, $form_values) { +function taxonomy_form_term_submit($form_values, $form, &$form_state) { switch (taxonomy_save_term($form_values)) { case SAVED_NEW: drupal_set_message(t('Created new term %term.', array('%term' => $form_values['name']))); @@ -487,7 +490,10 @@ function taxonomy_form_term_submit($form_id, $form_values) { watchdog('taxonomy', 'Updated term %term.', array('%term' => $form_values['name']), WATCHDOG_NOTICE, l(t('edit'), 'admin/content/taxonomy/edit/term/'. $form_values['tid'])); break; } - return 'admin/content/taxonomy'; + + $form_state['tid'] = $form_values['tid']; + $form_state['redirect'] = 'admin/content/taxonomy'; + return; } /** @@ -623,11 +629,12 @@ function taxonomy_term_confirm_delete($tid) { t('Cancel')); } -function taxonomy_term_confirm_delete_submit($form_id, $form_values) { +function taxonomy_term_confirm_delete_submit($form_values, $form, &$form_state) { taxonomy_del_term($form_values['tid']); drupal_set_message(t('Deleted term %name.', array('%name' => $form_values['name']))); watchdog('taxonomy', 'Deleted term %name.', array('%name' => $form_values['name']), WATCHDOG_NOTICE); - return 'admin/content/taxonomy'; + $form_state['redirect'] = 'admin/content/taxonomy'; + return; } /** diff --git a/modules/throttle/throttle.module b/modules/throttle/throttle.module index ef9b29003..81bb1fd00 100644 --- a/modules/throttle/throttle.module +++ b/modules/throttle/throttle.module @@ -156,7 +156,7 @@ function throttle_admin_settings() { return system_settings_form($form); } -function throttle_admin_settings_validate($form_id, $form_values) { +function throttle_admin_settings_validate($form_values, $form, &$form_state) { if (!is_numeric($form_values['throttle_anonymous']) || $form_values['throttle_anonymous'] < 0) { form_set_error('throttle_anonymous', t("%value is not a valid auto-throttle setting. Please enter a positive numeric value.", array('%value' => $form_values['throttle_anonymous']))); } diff --git a/modules/upload/upload.module b/modules/upload/upload.module index 85277fdd1..b7127aa2f 100644 --- a/modules/upload/upload.module +++ b/modules/upload/upload.module @@ -119,7 +119,7 @@ function upload_init() { /** * Form API callback to validate the upload settings form. */ -function upload_admin_settings_validate($form_id, $form_values) { +function upload_admin_settings_validate($form_values, $form, &$form_state) { if (($form_values['upload_max_resolution'] != '0')) { if (!preg_match('/^[0-9]+x[0-9]+$/', $form_values['upload_max_resolution'])) { form_set_error('upload_max_resolution', t('The maximum allowed image size expressed as WIDTHxHEIGHT (e.g. 640x480). Set to 0 for no restriction.')); @@ -326,7 +326,7 @@ function _upload_prepare(&$node) { // Scale image uploads. $file = _upload_image($file); - $key = 'upload_'. (isset($_SESSION['file_previews']) ? 0 : count($_SESSION['file_previews'])); + $key = 'upload_'. (!isset($_SESSION['file_previews']) ? 0 : count($_SESSION['file_previews'])); $file->fid = $key; $file->source = $key; $file->list = variable_get('upload_list_default', 1); @@ -813,7 +813,13 @@ function _upload_form($node) { '#suffix' => '</div>', ); $form['new']['upload'] = array('#type' => 'file', '#title' => t('Attach new file'), '#size' => 40); - $form['new']['attach'] = array('#type' => 'button', '#value' => t('Attach'), '#name' => 'attach', '#id' => 'attach-button'); + $form['new']['attach'] = array( + '#type' => 'submit', + '#value' => t('Attach'), + '#name' => 'attach', + '#id' => 'attach-button', + '#submit' => array(), + ); // The class triggers the js upload behaviour. $form['attach-url'] = array('#type' => 'hidden', '#value' => url('upload/js', array('absolute' => TRUE)), '#attributes' => array('class' => 'upload')); } @@ -872,7 +878,7 @@ function _upload_image($file) { $info = image_get_info($file->filepath); if ($info) { - list($width, $height) = explode('x', variable_get('upload_max_resolution', 0)); + list($width, $height) = explode('x', variable_get('upload_max_resolution', '0x0')); if ($width && $height) { $result = image_scale($file->filepath, $file->filepath, $width, $height); if ($result) { @@ -906,9 +912,9 @@ function upload_js() { '#tree' => FALSE, '#parents' => array(), ); - $GLOBALS['form_button_counter'] = array(0, 0); drupal_alter('form', $form, 'upload_js'); - $form = form_builder('upload_js', $form); + $form_state = array('submitted' => FALSE); + $form = form_builder('upload_js', $form, $form_state); $output = theme('status_messages') . drupal_render($form); // We send the updated file attachments form. print drupal_to_js(array('status' => TRUE, 'data' => $output)); diff --git a/modules/user/user.module b/modules/user/user.module index ff3ee7b33..3b36beba2 100644 --- a/modules/user/user.module +++ b/modules/user/user.module @@ -313,35 +313,34 @@ function user_validate_mail($mail) { } } -function user_validate_picture($file, &$edit, $user) { - global $form_values; - // Initialize the picture: - $form_values['picture'] = $user->picture; - - // Check that uploaded file is an image, with a maximum file size - // and maximum height/width. - $info = image_get_info($file->filepath); - list($maxwidth, $maxheight) = explode('x', variable_get('user_picture_dimensions', '85x85')); - - if (!$info || !$info['extension']) { - form_set_error('picture_upload', t('The uploaded file was not an image.')); - } - else if (image_get_toolkit()) { - image_scale($file->filepath, $file->filepath, $maxwidth, $maxheight); - } - else if (filesize($file->filepath) > (variable_get('user_picture_file_size', '30') * 1000)) { - form_set_error('picture_upload', t('The uploaded image is too large; the maximum file size is %size kB.', array('%size' => variable_get('user_picture_file_size', '30')))); - } - else if ($info['width'] > $maxwidth || $info['height'] > $maxheight) { - form_set_error('picture_upload', t('The uploaded image is too large; the maximum dimensions are %dimensions pixels.', array('%dimensions' => variable_get('user_picture_dimensions', '85x85')))); - } +function user_validate_picture(&$form_values, $form, &$form_state) { + // If required, validate the uploaded picture. + if (isset($form['picture']) && ($file = file_check_upload('picture_upload'))) { + // Check that uploaded file is an image, with a maximum file size + // and maximum height/width. + $info = image_get_info($file->filepath); + list($maxwidth, $maxheight) = explode('x', variable_get('user_picture_dimensions', '85x85')); - if (!form_get_errors()) { - if ($file = file_save_upload('picture_upload', variable_get('user_picture_path', 'pictures') .'/picture-'. $user->uid .'.'. $info['extension'], 1)) { - $form_values['picture'] = $file->filepath; + if (!$info || !$info['extension']) { + form_set_error('picture_upload', t('The uploaded file was not an image.')); } - else { - form_set_error('picture_upload', t("Failed to upload the picture image; the %directory directory doesn't exist or is not writable.", array('%directory' => variable_get('user_picture_path', 'pictures')))); + else if (image_get_toolkit()) { + image_scale($file->filepath, $file->filepath, $maxwidth, $maxheight); + } + else if (filesize($file->filepath) > (variable_get('user_picture_file_size', '30') * 1000)) { + form_set_error('picture_upload', t('The uploaded image is too large; the maximum file size is %size kB.', array('%size' => variable_get('user_picture_file_size', '30')))); + } + else if ($info['width'] > $maxwidth || $info['height'] > $maxheight) { + form_set_error('picture_upload', t('The uploaded image is too large; the maximum dimensions are %dimensions pixels.', array('%dimensions' => variable_get('user_picture_dimensions', '85x85')))); + } + + if (!form_get_errors()) { + if ($file = file_save_upload('picture_upload', variable_get('user_picture_path', 'pictures') .'/picture-'. $form['#uid'] .'.'. $info['extension'], 1)) { + $form_values['picture'] = $file->filepath; + } + else { + form_set_error('picture_upload', t("Failed to upload the picture image; the %directory directory doesn't exist or is not writable.", array('%directory' => variable_get('user_picture_path', 'pictures')))); + } } } } @@ -522,8 +521,8 @@ function user_login_block() { $form = array( '#action' => url($_GET['q'], array('query' => drupal_get_destination())), '#id' => 'user-login-form', - '#validate' => array('user_login_validate' => array()), - '#submit' => array('user_login_submit' => array()), + '#validate' => array('user_login_validate'), + '#submit' => array('user_login_submit'), ); $form['name'] = array('#type' => 'textfield', '#title' => t('Username'), @@ -661,7 +660,7 @@ function user_block($op = 'list', $delta = 0, $edit = array()) { function theme_user_picture($account) { if (variable_get('user_pictures', 0)) { - if ($account->picture && file_exists($account->picture)) { + if (!empty($account->picture) && file_exists($account->picture)) { $picture = file_create_url($account->picture); } else if (variable_get('user_picture_default', '')) { @@ -1056,7 +1055,7 @@ function user_login($msg = '') { return $form; } -function user_login_validate($form_id, $form_values) { +function user_login_validate($form_values, $form, &$form_state) { if ($form_values['name']) { if (user_is_blocked($form_values['name'])) { // blocked in user administration @@ -1077,7 +1076,7 @@ function user_login_validate($form_id, $form_values) { } } -function user_login_submit($form_id, $form_values) { +function user_login_submit($form_values, $form, &$form_state) { global $user; if ($user->uid) { watchdog('user', 'Session opened for %name.', array('%name' => $user->name)); @@ -1088,7 +1087,8 @@ function user_login_submit($form_id, $form_values) { user_module_invoke('login', $form_values, $user); sess_regenerate(); - return 'user/'. $user->uid; + $form_state['redirect'] = 'user/'. $user->uid; + return; } } @@ -1171,7 +1171,7 @@ function user_pass() { return $form; } -function user_pass_validate($form_id, $form_values) { +function user_pass_validate($form_values, $form, &$form_state) { $name = trim($form_values['name']); if (valid_email_address($name)) { $account = user_load(array('mail' => $name, 'status' => 1)); @@ -1180,14 +1180,14 @@ function user_pass_validate($form_id, $form_values) { $account = user_load(array('name' => $name, 'status' => 1)); } if (isset($account->uid)) { - form_set_value(array('#parents' => array('account')), $account); + form_set_value(array('#parents' => array('account')), $account, $form_state); } else { form_set_error('name', t('Sorry, %name is not recognized as a user name or an e-mail address.', array('%name' => $name))); } } -function user_pass_submit($form_id, $form_values) { +function user_pass_submit($form_values, $form, &$form_state) { global $base_url; $account = $form_values['account']; @@ -1207,7 +1207,8 @@ function user_pass_submit($form_id, $form_values) { watchdog('user', 'Error mailing password reset instructions to %name at %email.', array('%name' => $account->name, '%email' => $account->mail), WATCHDOG_ERROR); drupal_set_message(t('Unable to send mail. Please contact the site admin.')); } - return 'user'; + $form_state['redirect'] = 'user'; + return; } /** @@ -1326,15 +1327,16 @@ function user_register() { $form = array_merge($form, $extra); } $form['submit'] = array('#type' => 'submit', '#value' => t('Create new account'), '#weight' => 30); + $form['#validate'][] = 'user_register_validate'; return $form; } -function user_register_validate($form_id, $form_values) { +function user_register_validate($form_values, $form, &$form_state) { user_module_invoke('validate', $form_values, $form_values, 'account'); } -function user_register_submit($form_id, $form_values) { +function user_register_submit($form_values, $form, &$form_state) { global $base_url; $admin = user_access('administer users'); @@ -1357,7 +1359,8 @@ function user_register_submit($form_id, $form_values) { if (!$admin && array_intersect(array_keys($form_values), array('uid', 'roles', 'init', 'session', 'status'))) { watchdog('security', 'Detected malicious attempt to alter protected user fields.', array(), WATCHDOG_WARNING); - return 'user/register'; + $form_state['redirect'] = 'user/register'; + return; } //the unset below is needed to prevent these form values from being saved as user data unset($form_values['form_token'], $form_values['submit'], $form_values['op'], $form_values['notify'], $form_values['form_id'], $form_values['affiliates'], $form_values['destination']); @@ -1368,6 +1371,8 @@ function user_register_submit($form_id, $form_values) { $merge_data['status'] = variable_get('user_register', 1) == 1; } $account = user_save('', array_merge($form_values, $merge_data)); + $form_state['user'] = $account; + watchdog('user', 'New user: %name (%email).', array('%name' => $name, '%email' => $mail), WATCHDOG_NOTICE, l(t('edit'), 'user/'. $account->uid .'/edit')); $variables = array('!username' => $name, '!site' => variable_get('site_name', 'Drupal'), '!password' => $pass, '!uri' => $base_url, '!uri_brief' => substr($base_url, strlen('http://')), '!mailto' => $mail, '!date' => format_date(time()), '!login_uri' => url('user', array('absolute' => TRUE)), '!edit_uri' => url('user/'. $account->uid .'/edit', array('absolute' => TRUE)), '!login_url' => user_pass_reset_url($account)); @@ -1378,9 +1383,11 @@ function user_register_submit($form_id, $form_values) { if (variable_get('user_email_verification', TRUE)) { drupal_set_message(t('</p><p> Your password is <strong>%pass</strong>. You may change your password below.</p>', array('%pass' => $pass))); } + user_authenticate($account->name, trim($pass)); - return 'user/1/edit'; + $form_state['redirect'] = 'user/1/edit'; + return; } else { if ($admin && !$notify) { @@ -1392,7 +1399,8 @@ function user_register_submit($form_id, $form_values) { $body = _user_mail_text('welcome_body', $variables); drupal_mail('user-register-welcome', $mail, $subject, $body, $from); user_authenticate($account->name, trim($pass)); - return ''; + $form_state['redirect'] = ''; + return; } else if ($account->status || $notify) { // Create new user account, no administrator approval required. @@ -1406,7 +1414,8 @@ function user_register_submit($form_id, $form_values) { } else { drupal_set_message(t('Your password and further instructions have been sent to your e-mail address.')); - return ''; + $form_state['redirect'] = ''; + return; } } else { @@ -1498,7 +1507,9 @@ function user_edit_form($uid, $edit, $register = FALSE) { $form['picture']['picture_delete'] = array('#type' => 'hidden'); } $form['picture']['picture_upload'] = array('#type' => 'file', '#title' => t('Upload picture'), '#size' => 48, '#description' => t('Your virtual face or picture. Maximum dimensions are %dimensions and the maximum size is %size kB.', array('%dimensions' => variable_get('user_picture_dimensions', '85x85'), '%size' => variable_get('user_picture_file_size', '30'))) .' '. variable_get('user_picture_guidelines', '')); + $form['#validate'][] = 'user_validate_picture'; } + $form['#uid'] = $uid; return $form; } @@ -1528,11 +1539,6 @@ function _user_edit_validate($uid, &$edit) { else if (drupal_is_denied('mail', $edit['mail'])) { form_set_error('mail', t('The e-mail address %email has been denied access.', array('%email' => $edit['mail']))); } - - // If required, validate the uploaded picture. - if ($file = file_check_upload('picture_upload')) { - user_validate_picture($file, $edit, $user); - } } function _user_edit_submit($uid, &$edit) { @@ -1587,6 +1593,7 @@ function user_edit($category = 'account') { $form['delete'] = array('#type' => 'submit', '#value' => t('Delete'), '#weight' => 31); } $form['#attributes']['enctype'] = 'multipart/form-data'; + $form['#validate'][] = 'user_edit_validate'; drupal_set_title(check_plain($account->name)); return $form; @@ -1618,7 +1625,7 @@ function user_delete($edit, $uid) { module_invoke_all('user', 'delete', $edit, $account); } -function user_edit_validate($form_id, $form_values) { +function user_edit_validate($form_values, $form, &$form_state) { user_module_invoke('validate', $form_values, $form_values['_account'], $form_values['_category']); // Validate input to ensure that non-privileged users can't alter protected data. if ((!user_access('administer users') && array_intersect(array_keys($form_values), array('uid', 'init', 'session'))) || (!user_access('administer access control') && isset($form_values['roles']))) { @@ -1628,7 +1635,7 @@ function user_edit_validate($form_id, $form_values) { } } -function user_edit_submit($form_id, $form_values) { +function user_edit_submit($form_values, $form, &$form_state) { $account = $form_values['_account']; $category = $form_values['_category']; unset($form_values['_account'], $form_values['op'], $form_values['submit'], $form_values['delete'], $form_values['form_token'], $form_values['form_id'], $form_values['_category']); @@ -1639,7 +1646,8 @@ function user_edit_submit($form_id, $form_values) { cache_clear_all(); drupal_set_message(t('The changes have been saved.')); - return 'user/'. $account->uid; + $form_state['redirect'] = 'user/'. $account->uid; + return; } function user_view($account) { @@ -1701,8 +1709,8 @@ function user_admin_check_user() { $form['user']['test'] = array('#type' => 'textfield', '#title' => '', '#description' => t('Enter a username to check if it will be denied or allowed.'), '#size' => 30, '#maxlength' => USERNAME_MAX_LENGTH); $form['user']['type'] = array('#type' => 'hidden', '#value' => 'user'); $form['user']['submit'] = array('#type' => 'submit', '#value' => t('Check username')); - $form['#submit']['user_admin_access_check_submit'] = array(); - $form['#validate']['user_admin_access_check_validate'] = array(); + $form['#submit'][] = 'user_admin_access_check_submit'; + $form['#validate'][] = 'user_admin_access_check_validate'; $form['#theme'] = 'user_admin_access_check'; return $form; } @@ -1712,8 +1720,8 @@ function user_admin_check_mail() { $form['mail']['test'] = array('#type' => 'textfield', '#title' => '', '#description' => t('Enter an e-mail address to check if it will be denied or allowed.'), '#size' => 30, '#maxlength' => EMAIL_MAX_LENGTH); $form['mail']['type'] = array('#type' => 'hidden', '#value' => 'mail'); $form['mail']['submit'] = array('#type' => 'submit', '#value' => t('Check e-mail')); - $form['#submit']['user_admin_access_check_submit'] = array(); - $form['#validate']['user_admin_access_check_validate'] = array(); + $form['#submit'][] = 'user_admin_access_check_submit'; + $form['#validate'][] = 'user_admin_access_check_validate'; $form['#theme'] = 'user_admin_access_check'; return $form; } @@ -1723,8 +1731,8 @@ function user_admin_check_host() { $form['host']['test'] = array('#type' => 'textfield', '#title' => '', '#description' => t('Enter a hostname or IP address to check if it will be denied or allowed.'), '#size' => 30, '#maxlength' => 64); $form['host']['type'] = array('#type' => 'hidden', '#value' => 'host'); $form['host']['submit'] = array('#type' => 'submit', '#value' => t('Check hostname')); - $form['#submit']['user_admin_access_check_submit'] = array(); - $form['#validate']['user_admin_access_check_validate'] = array(); + $form['#submit'][] = 'user_admin_access_check_submit'; + $form['#validate'][] = 'user_admin_access_check_validate'; $form['#theme'] = 'user_admin_access_check'; return $form; } @@ -1739,13 +1747,13 @@ function user_admin_access_check() { return $output; } -function user_admin_access_check_validate($form_id, $form_values) { +function user_admin_access_check_validate($form_values, $form, &$form_state) { if (empty($form_values['test'])) { form_set_error($form_values['type'], t('No value entered. Please enter a test string and try again.')); } } -function user_admin_access_check_submit($form_id, $form_values) { +function user_admin_access_check_submit($form_values, $form, &$form_state) { switch ($form_values['type']) { case 'user': if (drupal_is_denied('user', $form_values['test'])) { @@ -1816,10 +1824,11 @@ function user_admin_access_delete_confirm($aid = 0) { return $output; } -function user_admin_access_delete_confirm_submit($form_id, $form_values) { +function user_admin_access_delete_confirm_submit($form_values, $form, &$form_state) { db_query('DELETE FROM {access} WHERE aid = %d', $form_values['aid']); drupal_set_message(t('The access rule has been deleted.')); - return 'admin/user/rules'; + $form_state['redirect'] = 'admin/user/rules'; + return; } /** @@ -2008,7 +2017,7 @@ function theme_user_admin_perm($form) { return $output; } -function user_admin_perm_submit($form_id, $form_values) { +function user_admin_perm_submit($form_values, $form, &$form_state) { // Save permissions: $result = db_query('SELECT * FROM {role}'); while ($role = db_fetch_object($result)) { @@ -2073,13 +2082,13 @@ function user_admin_role() { '#type' => 'submit', '#value' => t('Add role'), ); - $form['#submit']['user_admin_role_submit'] = array(); - $form['#validate']['user_admin_role_validate'] = array(); + $form['#submit'][] = 'user_admin_role_submit'; + $form['#validate'][] = 'user_admin_role_validate'; } return $form; } -function user_admin_role_validate($form_id, $form_values) { +function user_admin_role_validate($form_values, $form, &$form_state) { if ($form_values['name']) { if ($form_values['op'] == t('Save role')) { if (db_result(db_query("SELECT COUNT(*) FROM {role} WHERE name = '%s' AND rid != %d", $form_values['name'], $form_values['rid']))) { @@ -2097,7 +2106,7 @@ function user_admin_role_validate($form_id, $form_values) { } } -function user_admin_role_submit($form_id, $form_values) { +function user_admin_role_submit($form_values, $form, &$form_state) { if ($form_values['op'] == t('Save role')) { db_query("UPDATE {role} SET name = '%s' WHERE rid = %d", $form_values['name'], $form_values['rid']); drupal_set_message(t('The role has been renamed.')); @@ -2114,7 +2123,8 @@ function user_admin_role_submit($form_id, $form_values) { db_query("INSERT INTO {role} (name) VALUES ('%s')", $form_values['name']); drupal_set_message(t('The role has been added.')); } - return 'admin/user/roles'; + $form_state['redirect'] = 'admin/user/roles'; + return; } function theme_user_admin_new_role($form) { @@ -2248,7 +2258,7 @@ function theme_user_admin_account($form) { /** * Submit the user administration update form. */ -function user_admin_account_submit($form_id, $form_values) { +function user_admin_account_submit($form_values, $form, &$form_state) { $operations = module_invoke_all('user_operations'); $operation = $operations[$form_values['operation']]; // Filter out unchecked accounts. @@ -2267,7 +2277,7 @@ function user_admin_account_submit($form_id, $form_values) { } } -function user_admin_account_validate($form_id, $form_values) { +function user_admin_account_validate($form_values, $form, &$form_state) { $form_values['accounts'] = array_filter($form_values['accounts']); if (count($form_values['accounts']) == 0) { form_set_error('', t('No users selected.')); @@ -2419,14 +2429,15 @@ function user_multiple_delete_confirm() { t('Delete all'), t('Cancel')); } -function user_multiple_delete_confirm_submit($form_id, $form_values) { +function user_multiple_delete_confirm_submit($form_values, $form, &$form_state) { if ($form_values['confirm']) { foreach ($form_values['accounts'] as $uid => $value) { user_delete($form_values, $uid); } drupal_set_message(t('The users have been deleted.')); } - return 'admin/user/user'; + $form_state['redirect'] = 'admin/user/user'; + return; } function user_admin_settings() { @@ -2787,7 +2798,7 @@ function theme_user_filters($form) { /** * Process result from user administration filter form. */ -function user_filter_form_submit($form_id, $form_values) { +function user_filter_form_submit($form_values, $form, &$form_state) { $op = $form_values['op']; $filters = user_filters(); switch ($op) { @@ -2811,7 +2822,8 @@ function user_filter_form_submit($form_id, $form_values) { return; } - return 'admin/user/user'; + $form_state['redirect'] = 'admin/user/user'; + return; } |