Commit 4b635f6d authored by Dries's avatar Dries

- Patch #128081 by Eaton: remove #base, paving the path for a simpler form API.

parent f6929dcc
......@@ -248,7 +248,7 @@ function drupal_process_form($form_id, &$form) {
$form_button_counter = array(0, 0);
drupal_prepare_form($form_id, $form);
if (($form['#programmed']) || (!empty($_POST) && (($_POST['form_id'] == $form_id) || ($_POST['form_id'] == $form['#base'])))) {
if (($form['#programmed']) || (!empty($_POST) && (($_POST['form_id'] == $form_id)))) {
drupal_validate_form($form_id, $form);
// IE does not send a button value when there is only one submit button (and no non-submit buttons)
// and you submit by pressing enter.
......@@ -307,11 +307,6 @@ function drupal_prepare_form($form_id, &$form) {
);
}
// If $base is set, it is used in place of $form_id when constructing validation,
// submission, and theming functions. Useful for mapping many similar or duplicate
// forms with different $form_ids to the same processing functions.
$base = isset($form['#base']) ? $form['#base'] : '';
// Add a token, based on either #token or form_id, to any form displayed to
// authenticated users. This ensures that any submitted form was actually
// requested previously by the user and protects against cross site request
......@@ -347,9 +342,6 @@ function drupal_prepare_form($form_id, &$form) {
if (function_exists($form_id .'_validate')) {
$form['#validate'] = array($form_id .'_validate' => array());
}
elseif (function_exists($base .'_validate')) {
$form['#validate'] = array($base .'_validate' => array());
}
}
if (!isset($form['#submit'])) {
......@@ -357,9 +349,6 @@ function drupal_prepare_form($form_id, &$form) {
// We set submit here so that it can be altered.
$form['#submit'] = array($form_id .'_submit' => array());
}
elseif (function_exists($base .'_submit')) {
$form['#submit'] = array($base .'_submit' => array());
}
}
foreach (module_implements('form_alter') as $module) {
......@@ -469,15 +458,11 @@ function drupal_submit_form($form_id, $form) {
*/
function drupal_render_form($form_id, &$form) {
// Don't override #theme if someone already set it.
$base = isset($form['#base']) ? $form['#base'] : '';
if (!isset($form['#theme'])) {
if (theme_get_function($form_id)) {
$form['#theme'] = $form_id;
}
elseif (theme_get_function($base)) {
$form['#theme'] = $base;
}
}
if (isset($form['#pre_render'])) {
......
......@@ -75,7 +75,9 @@ function _locale_admin_manage_screen() {
'#default_value' => $isdefault,
);
$form['submit'] = array('#type' => 'submit', '#value' => t('Save configuration'));
$form['#base'] = 'locale_admin_manage_screen';
$form['#submit']['locale_admin_manage_screen_submit'] = array();
$form['#validate']['locale_admin_manage_screen_validate'] = array();
$form['#theme'] = 'locale_admin_manage_screen';
return $form;
}
......@@ -162,7 +164,9 @@ function locale_custom_language_form() {
);
$form['custom language']['submit'] = array('#type' => 'submit', '#value' => t('Add custom language'));
// Use the validation and submit functions of the add language form.
$form['#base'] = 'locale_add_language_form';
$form['#submit']['locale_add_language_form_submit'] = array();
$form['#validate']['locale_add_language_form_validate'] = array();
$form['#theme'] = 'locale_add_language_form';
return $form;
}
......@@ -294,7 +298,9 @@ function _locale_export_pot_form() {
'#description' => t('Generate a gettext Portable Object Template (.pot) file with all the interface strings from the Drupal locale database.'),
);
$form['export']['submit'] = array('#type' => 'submit', '#value' => t('Export'));
$form['#base'] = '_locale_export_po_form';
$form['#submit']['_locale_export_po_form_submit'] = array();
$form['#validate']['_locale_export_po_form_validate'] = array();
$form['#theme'] = '_locale_export_po_form';
return $form;
}
......
......@@ -1052,7 +1052,9 @@ function aggregator_page_category() {
}
function aggregator_page_list($sql, $header, $categorize) {
$form['#base'] = 'aggregator_page_list';
$form['#submit']['aggregator_page_list_submit'] = array();
$form['#validate']['aggregator_page_list_validate'] = array();
$form['#theme'] = 'aggregator_page_list';
$form['header'] = array('#value' => $header);
$result = pager_query($sql, 20);
$categories = array();
......
......@@ -912,7 +912,9 @@ function book_admin_orphan() {
else {
$form['error'] = array('#value' => '<p>'. t('There are no orphan pages.') .'</p>');
}
$form['#base'] = 'book_admin_edit';
$form['#submit']['book_admin_edit_submit'] = array();
$form['#validate']['book_admin_edit_validate'] = array();
$form['#theme'] = 'book_admin_edit';
return $form;
}
......
......@@ -473,7 +473,9 @@ function forum_form_container($edit = array()) {
$form['delete'] = array('#type' => 'submit', '#value' => t('Delete'));
$form['tid'] = array('#type' => 'value', '#value' => $edit['tid']);
}
$form['#base'] = 'forum_form';
$form['#submit']['forum_form_submit'] = array();
$form['#validate']['forum_form_validate'] = array();
$form['#theme'] = 'forum_form';
return $form;
}
......@@ -524,7 +526,9 @@ function forum_form_forum($edit = array()) {
$form['delete'] = array('#type' => 'submit', '#value' => t('Delete'));
$form['tid'] = array('#type' => 'hidden', '#value' => $edit['tid']);
}
$form['#base'] = 'forum_form';
$form['#submit']['forum_form_submit'] = array();
$form['#validate']['forum_form_validate'] = array();
$form['#theme'] = 'forum_form';
return $form;
}
......
......@@ -324,7 +324,9 @@ 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['#base'] = 'menu_edit_item_form';
$form['#submit']['menu_edit_item_form_submit'] = array();
$form['#validate']['menu_edit_item_form_validate'] = array();
$form['#theme'] = 'menu_edit_item_form';
return $form;
}
......
......@@ -2017,7 +2017,9 @@ function node_form($node, $form_values = NULL) {
$form['delete'] = array('#type' => 'button', '#value' => t('Delete'), '#weight' => 50);
}
$form['#after_build'] = array('node_form_add_preview');
$form['#base'] = 'node_form';
$form['#submit']['node_form_submit'] = array();
$form['#validate']['node_form_validate'] = array();
$form['#theme'] = 'node_form';
return $form;
}
......
......@@ -183,7 +183,9 @@ function path_set_alias($path = NULL, $alias = NULL, $pid = NULL) {
* Return a form for editing or creating an individual URL alias.
*/
function path_form($edit = '') {
$form['#base'] = 'path_form';
$form['#submit']['path_form_submit'] = array();
$form['#validate']['path_form_validate'] = array();
$form['#theme'] = 'path_form';
$form['src'] = array(
'#type' => 'textfield',
......
......@@ -1052,7 +1052,9 @@ 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['#base'] = 'search_box_form';
$form['#submit']['search_box_form_submit'] = array();
$form['#validate']['search_box_form_validate'] = array();
$form['#theme'] = 'search_box_form';
return $form;
}
......
......@@ -1075,7 +1075,9 @@ 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['#base'] = 'system_settings_form';
$form['#submit']['system_settings_form_submit'] = array();
$form['#validate']['system_settings_form_validate'] = array();
$form['#theme'] = 'system_settings_form';
return $form;
}
......@@ -2163,7 +2165,9 @@ function confirm_form($form, $question, $path, $description = NULL, $yes = NULL,
$form['actions'] = array('#prefix' => '<div class="container-inline">', '#suffix' => '</div>');
$form['actions']['submit'] = array('#type' => 'submit', '#value' => $yes ? $yes : t('Confirm'));
$form['actions']['cancel'] = array('#value' => $cancel);
$form['#base'] = 'confirm_form';
$form['#submit']['confirm_form_submit'] = array();
$form['#validate']['confirm_form_validate'] = array();
$form['#theme'] = 'confirm_form';
return $form;
}
......
......@@ -1652,7 +1652,9 @@ 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['#base'] = 'user_admin_access_check';
$form['#submit']['user_admin_access_check_submit'] = array();
$form['#validate']['user_admin_access_check_validate'] = array();
$form['#theme'] = 'user_admin_access_check';
return $form;
}
......@@ -1661,7 +1663,9 @@ 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['#base'] = 'user_admin_access_check';
$form['#submit']['user_admin_access_check_submit'] = array();
$form['#validate']['user_admin_access_check_validate'] = array();
$form['#theme'] = 'user_admin_access_check';
return $form;
}
......@@ -1670,7 +1674,9 @@ 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['#base'] = 'user_admin_access_check';
$form['#submit']['user_admin_access_check_submit'] = array();
$form['#validate']['user_admin_access_check_validate'] = array();
$form['#theme'] = 'user_admin_access_check';
return $form;
}
......@@ -2020,7 +2026,9 @@ function user_admin_role() {
'#type' => 'submit',
'#value' => t('Add role'),
);
$form['#base'] = 'user_admin_role';
$form['#submit']['user_admin_role_submit'] = array();
$form['#validate']['user_admin_role_validate'] = array();
$form['#theme'] = 'user_admin_role';
}
return $form;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment