Commit 1fe90cba authored by Dries's avatar Dries

- Patch #146667 by Eaton: correct builder argument ordering, eliminate redundant arguments

parent 712c5758
......@@ -1742,15 +1742,15 @@ function drupal_add_js($data = NULL, $type = 'module', $scope = 'header', $defer
* @return
* All JavaScript code segments and includes for the scope as HTML tags.
*/
function drupal_get_js($scope = 'header', $javascript = NULL) {
function drupal_get_js($scope = 'header', $javascript = NULL) {
if (!isset($javascript)) {
$javascript = drupal_add_js(NULL, NULL, $scope);
}
if (count($javascript) < 1) {
return '';
}
}
$output = '';
$preprocessed = '';
$no_preprocess = array('core' => '', 'module' => '', 'theme' => '');
......@@ -1760,7 +1760,7 @@ function drupal_get_js($scope = 'header', $javascript = NULL) {
$is_writable = is_dir($directory) && is_writable($directory) && (variable_get('file_downloads', FILE_DOWNLOADS_PUBLIC) == FILE_DOWNLOADS_PUBLIC);
foreach ($javascript as $type => $data) {
if (!$data) continue;
switch ($type) {
......@@ -1776,27 +1776,27 @@ function drupal_get_js($scope = 'header', $javascript = NULL) {
// If JS preprocessing is off, we still need to output the scripts.
// Additionally, go through any remaining scripts if JS preprocessing is on and output the non-cached ones.
foreach ($data as $path => $info) {
if (!$info['preprocess'] || !$is_writable || !$preprocess_js) {
if (!$info['preprocess'] || !$is_writable || !$preprocess_js) {
$no_preprocess[$type] .= '<script type="text/javascript"'. ($info['defer'] ? ' defer="defer"' : '') .' src="'. base_path() . $path . ($info['cache'] ? '' : '?'. time()) ."\"></script>\n";
}
else {
else {
$files[$path] = $info;
}
}
}
}
// Aggregate any remaining JS files that haven't already been output.
if ($is_writable && $preprocess_js && count($files) > 0) {
if ($is_writable && $preprocess_js && count($files) > 0) {
$filename = md5(serialize($files)) .'.js';
$preprocess_file = drupal_build_js_cache($files, $filename);
$preprocessed .= '<script type="text/javascript" src="'. base_path() . $preprocess_file .'"></script>'. "\n";
}
// Keep the order of JS files consistent as some are preprocessed and others are not.
// Make sure any inline or JS setting variables appear last after libraries have loaded.
$output = $preprocessed . implode('', $no_preprocess) . $output;
return $output;
}
......@@ -1818,9 +1818,9 @@ function drupal_build_js_cache($files, $filename) {
file_check_directory($jspath, FILE_CREATE_DIRECTORY);
if (!file_exists($jspath .'/'. $filename)) {
// Build aggregate JS file.
foreach ($files as $path => $info) {
if ($info['preprocess']) {
// Build aggregate JS file.
foreach ($files as $path => $info) {
if ($info['preprocess']) {
// Append a ';' after each JS file to prevent them from running together.
$contents .= _drupal_compress_js(file_get_contents($path). ';');
}
......@@ -1858,8 +1858,8 @@ function _drupal_compress_js($script) {
$script = _packer_apply($script, $regexps, TRUE);
return $script;
}
}
/**
* Multi-regexp replacements.
*
......@@ -1887,7 +1887,7 @@ function _packer_apply($script, $regexps, $escape = FALSE) {
// Count the number of matching groups (including the whole).
$length = 1 + preg_match_all('/(?<!\\\\)\((?!\?)/', $expression, $out);
// Treat only strings $replacement
if (is_string($replacement)) {
// Does the pattern deal with sub-expressions?
......@@ -1918,9 +1918,9 @@ function _packer_apply($script, $regexps, $escape = FALSE) {
$_regexps[] = array('/^$/', $replacement, $length);
}
}
// Execute the global replacement
// Build one mega-regexp out of the smaller ones.
$regexp = '/';
foreach ($_regexps as $_regexp) {
......@@ -1928,7 +1928,7 @@ function _packer_apply($script, $regexps, $escape = FALSE) {
$regexp .= '(' . substr($expression, 1, -1) . ')|';
}
$regexp = substr($regexp, 0, -1) . '/';
// In order to simplify the regexps that look e.g. for quoted strings, we
// remove all escaped characters (such as \' or \") from the data. Then, we
// put them back as they were.
......@@ -1983,7 +1983,7 @@ function _packer_escape_char($match, $return = FALSE) {
$_escaped[] = $match[1];
return '\\';
}
}
}
/**
* Helper function for _packer_apply().
......@@ -2003,12 +2003,12 @@ function _packer_replacement($arguments, $regexps = NULL, $escape = NULL) {
if (empty($arguments)) {
return '';
}
$i = 1; $j = 0;
// Loop through the regexps
while (isset($_regexps[$j])) {
list($expression, $replacement, $length) = $_regexps[$j++];
// Do we have a result?
if (isset($arguments[$i]) && ($arguments[$i] != '')) {
if (is_array($replacement) && isset($replacement['fn'])) {
......@@ -2043,7 +2043,7 @@ function _packer_unescape_char($match, $escaped = NULL) {
else {
return '\\'. array_shift($_escaped);
}
}
}
/**
* Helper function for _packer_replacement().
......
......@@ -75,6 +75,10 @@ function drupal_get_form($form_id) {
// to build it from scratch.
if (!isset($form)) {
$form_state['post'] = $_POST;
array_shift($args);
array_unshift($args, $form_state);
array_unshift($args, $form_id);
$form = call_user_func_array('drupal_retrieve_form', $args);
$form_build_id = 'form-'. md5(mt_rand());
$form['#build_id'] = $form_build_id;
......@@ -109,7 +113,9 @@ function drupal_get_form($form_id) {
// other variables passed into drupal_get_form().
if (!empty($form_state['rebuild']) || !empty($form_state['storage'])) {
$args[] = $form_state;
array_shift($args);
array_unshift($args, $form_state);
array_unshift($args, $form_id);
$form = call_user_func_array('drupal_retrieve_form', $args);
// We need a new build_id for the new version of the form.
......@@ -182,8 +188,7 @@ function drupal_execute($form_id, &$form_state) {
// the $form_state to be the last parameter, while drupal_execute()
// always takes it in as the second parameter.
$args = array_slice($args, 3);
array_unshift($args, $form_id);
$args[] = $form_state;
$args[1] = $form_state;
$form = call_user_func_array('drupal_retrieve_form', $args);
$form['#post'] = $form_state['values'];
......@@ -200,10 +205,12 @@ function drupal_execute($form_id, &$form_state) {
* Modules that need to generate the same form (or very similar forms)
* using different $form_ids can implement hook_forms(), which maps
* different $form_id values to the proper form constructor function.
* @param $form_state
* A keyed array containing the current state of the form.
* @param ...
* Any additional arguments needed by the form constructor function.
*/
function drupal_retrieve_form($form_id) {
function drupal_retrieve_form($form_id, &$form_state) {
static $forms;
// We save two copies of the incoming arguments: one for modules to use
......@@ -214,6 +221,9 @@ function drupal_retrieve_form($form_id) {
$args = func_get_args();
$saved_args = $args;
array_shift($args);
if (isset($form_state)) {
array_shift($args);
}
// We first check to see if there's a function named after the $form_id.
// If there is, we simply pass the arguments on to it to get the form.
......@@ -240,6 +250,9 @@ function drupal_retrieve_form($form_id) {
$callback = $form_definition['callback'];
}
}
array_unshift($args, $form_state);
// If $callback was returned by a hook_forms() implementation, call it.
// Otherwise, call the function named after the form id.
$form = call_user_func_array(isset($callback) ? $callback : $form_id, $args);
......@@ -613,7 +626,7 @@ function form_execute_handlers($type, &$form, &$form_state) {
$batch['sets'][] = array('form_submit' => $function);
}
else {
$function($form, $form_state, $form_state['values']);
$function($form, $form_state);
}
$return = TRUE;
}
......@@ -742,7 +755,7 @@ function form_builder($form_id, $form, &$form_state) {
// after normal input parsing has been completed.
if (isset($form['#after_build']) && !isset($form['#after_build_done'])) {
foreach ($form['#after_build'] as $function) {
$form = $function($form, $form_state['values'], $form_state);
$form = $function($form, $form_state);
$form['#after_build_done'] = TRUE;
}
}
......@@ -918,7 +931,7 @@ function _form_builder_ie_cleanup($form, &$form_state) {
*
* Specifically, if $form['#parents'] is array('foo', 'bar')
* and $value is 'baz' then this function will make
* $form_values['foo']['bar'] to be 'baz'.
* $form_state['values']['foo']['bar'] to be 'baz'.
*
* @param $form
* The form item. Keys used: #parents, #value
......@@ -933,7 +946,7 @@ function form_set_value($form, $value, &$form_state) {
* Helper function for form_set_value().
*
* We iterate over $parents and create nested arrays for them
* in $form_values if needed. Then we insert the value into
* in $form_state['values'] if needed. Then we insert the value into
* the right array.
*/
function _form_set_value(&$form_values, $form, $parents, $value) {
......
This diff is collapsed.
......@@ -208,7 +208,7 @@ function install_change_settings($profile = 'default', $install_locale = '') {
/**
* Form API array definition for install_settings.
*/
function install_settings_form($profile, $install_locale, $settings_file, $db_url, $db_type, $db_prefix, $db_user, $db_pass, $db_host, $db_port, $db_path) {
function install_settings_form(&$form_state, $profile, $install_locale, $settings_file, $db_url, $db_type, $db_prefix, $db_user, $db_pass, $db_host, $db_port, $db_path) {
if (empty($db_host)) {
$db_host = 'localhost';
}
......@@ -335,9 +335,9 @@ function install_settings_form($profile, $install_locale, $settings_file, $db_ur
/**
* Form API validate for install_settings form.
*/
function install_settings_form_validate($form, &$form_state, $form_values) {
function install_settings_form_validate($form, &$form_state) {
global $db_url;
_install_settings_form_validate($form_values['db_prefix'], $form_values['db_type'], $form_values['db_user'], $form_values['db_pass'], $form_values['db_host'], $form_values['db_port'], $form_values['db_path'], $form_values['settings_file'], $form_state, $form);
_install_settings_form_validate($form_state['values']['db_prefix'], $form_state['values']['db_type'], $form_state['values']['db_user'], $form_state['values']['db_pass'], $form_state['values']['db_host'], $form_state['values']['db_port'], $form_state['values']['db_path'], $form_state['values']['settings_file'], $form_state, $form);
}
/**
......@@ -387,16 +387,16 @@ function _install_settings_form_validate($db_prefix, $db_type, $db_user, $db_pas
/**
* Form API submit for install_settings form.
*/
function install_settings_form_submit($form, &$form_state, $form_values) {
function install_settings_form_submit($form, &$form_state) {
global $profile, $install_locale;
// Update global settings array and save
$settings['db_url'] = array(
'value' => $form_values['_db_url'],
'value' => $form_state['values']['_db_url'],
'required' => TRUE,
);
$settings['db_prefix'] = array(
'value' => $form_values['db_prefix'],
'value' => $form_state['values']['db_prefix'],
'required' => TRUE,
);
drupal_rewrite_settings($settings);
......@@ -444,7 +444,7 @@ function install_select_profile() {
}
}
function install_select_profile_form($profiles) {
function install_select_profile_form(&$form_state, $profiles) {
foreach ($profiles as $profile) {
include_once($profile->filename);
// Load profile details.
......@@ -531,7 +531,7 @@ function install_select_locale($profilename) {
}
}
function install_select_locale_form($locales) {
function install_select_locale_form(&$form_state, $locales) {
include_once './includes/locale.inc';
$languages = _locale_get_predefined_list();
foreach ($locales as $locale) {
......@@ -622,7 +622,7 @@ function install_tasks($profile, $task) {
$form_state = array('storage' => NULL, 'submitted' => FALSE);
$form = drupal_retrieve_form('install_configure_form');
$form = drupal_retrieve_form('install_configure_form', $form_state);
$form_build_id = md5(mt_rand());
$form['#build_id'] = $form_build_id;
drupal_prepare_form('install_configure_form', $form, $form_state);
......@@ -926,36 +926,42 @@ function install_configure_form() {
return $form;
}
function install_configure_form_validate($form, &$form_state, $form_values) {
if ($error = user_validate_name($form_values['account']['name'])) {
function install_configure_form_validate($form, &$form_state) {
if ($error = user_validate_name($form_state['values']['account']['name'])) {
form_error($form['admin_account']['account']['name'], $error);
}
if ($error = user_validate_mail($form_values['account']['mail'])) {
if ($error = user_validate_mail($form_state['values']['account']['mail'])) {
form_error($form['admin_account']['account']['mail'], $error);
}
if ($error = user_validate_mail($form_values['site_mail'])) {
if ($error = user_validate_mail($form_state['values']['site_mail'])) {
form_error($form['site_information']['site_mail'], $error);
}
}
function install_configure_form_submit($form, &$form_state, $form_values) {
function install_configure_form_submit($form, &$form_state) {
global $user;
variable_set('site_name', $form_values['site_name']);
variable_set('site_mail', $form_values['site_mail']);
variable_set('date_default_timezone', $form_values['date_default_timezone']);
variable_set('site_name', $form_state['values']['site_name']);
variable_set('site_mail', $form_state['values']['site_mail']);
variable_set('date_default_timezone', $form_state['values']['date_default_timezone']);
// Turn this off temporarily so that we can pass a password through.
variable_set('user_email_verification', FALSE);
user_register_submit($form, $form_state, $form_values['account']);
$form_state['old_values'] = $form_state['values'];
$form_state['values'] = $form_state['values']['account'];
user_register_submit($form, $form_state);
$form_state['values'] = $form_state['old_values'];
unset($form_state['old_values']);
variable_set('user_email_verification', TRUE);
if (isset($form_values['clean_url'])) {
variable_set('clean_url', $form_values['clean_url']);
if (isset($form_state['values']['clean_url'])) {
variable_set('clean_url', $form_state['values']['clean_url']);
}
// The user is now logged in, but has no session ID yet, which
// would be required later in the request, so remember it.
$user->sid = session_id();
return 'finished';
$form_state['redirect'] = 'finished';
}
install_main();
......@@ -50,7 +50,7 @@ Drupal.redirectFormButton = function (uri, button, handler) {
// Restore form submission
button.form.action = action;
button.form.target = target;
// Get response from iframe body
try {
response = (iframe.contentWindow || iframe.contentDocument || iframe).document.body.innerHTML;
......@@ -64,7 +64,7 @@ Drupal.redirectFormButton = function (uri, button, handler) {
catch (e) {
response = null;
}
response = Drupal.parseJson(response);
// Check response code
if (response.status == 0) {
......
......@@ -357,17 +357,17 @@ function aggregator_form_category($edit = array('title' => '', 'description' =>
/**
* Validate aggregator_form_feed form submissions.
*/
function aggregator_form_category_validate($form, &$form_state, $form_values) {
if ($form_values['op'] == t('Submit')) {
function aggregator_form_category_validate($form, &$form_state) {
if ($form_state['values']['op'] == t('Submit')) {
// Check for duplicate titles
if (isset($form_values['cid'])) {
$category = db_fetch_object(db_query("SELECT cid FROM {aggregator_category} WHERE title = '%s' AND cid != %d", $form_values['title'], $form_values['cid']));
if (isset($form_state['values']['cid'])) {
$category = db_fetch_object(db_query("SELECT cid FROM {aggregator_category} WHERE title = '%s' AND cid != %d", $form_state['values']['title'], $form_state['values']['cid']));
}
else {
$category = db_fetch_object(db_query("SELECT cid FROM {aggregator_category} WHERE title = '%s'", $form_values['title']));
$category = db_fetch_object(db_query("SELECT cid FROM {aggregator_category} WHERE title = '%s'", $form_state['values']['title']));
}
if ($category) {
form_set_error('title', t('A category named %category already exists. Please enter a unique title.', array('%category' => $form_values['title'])));
form_set_error('title', t('A category named %category already exists. Please enter a unique title.', array('%category' => $form_state['values']['title'])));
}
}
}
......@@ -376,23 +376,23 @@ function aggregator_form_category_validate($form, &$form_state, $form_values) {
* Process aggregator_form_category form submissions.
* @todo Add delete confirmation dialog.
*/
function aggregator_form_category_submit($form, &$form_state, $form_values) {
if ($form_values['op'] == t('Delete')) {
$title = $form_values['title'];
function aggregator_form_category_submit($form, &$form_state) {
if ($form_state['values']['op'] == t('Delete')) {
$title = $form_state['values']['title'];
// Unset the title:
unset($form_values['title']);
unset($form_state['values']['title']);
}
aggregator_save_category($form_values);
aggregator_save_category($form_state['values']);
menu_rebuild();
if (isset($form_values['cid'])) {
if (isset($form_values['title'])) {
drupal_set_message(t('The category %category has been updated.', array('%category' => $form_values['title'])));
if (isset($form_state['values']['cid'])) {
if (isset($form_state['values']['title'])) {
drupal_set_message(t('The category %category has been updated.', array('%category' => $form_state['values']['title'])));
if (arg(0) == 'admin') {
$form_state['redirect'] = 'admin/content/aggregator/';
return;
}
else {
$form_state['redirect'] = 'aggregator/categories/'. $form_values['cid'];
$form_state['redirect'] = 'aggregator/categories/'. $form_state['values']['cid'];
return;
}
}
......@@ -410,8 +410,8 @@ function aggregator_form_category_submit($form, &$form_state, $form_values) {
}
}
else {
watchdog('aggregator', 'Category %category added.', array('%category' => $form_values['title']), WATCHDOG_NOTICE, l(t('view'), 'admin/content/aggregator'));
drupal_set_message(t('The category %category has been added.', array('%category' => $form_values['title'])));
watchdog('aggregator', 'Category %category added.', array('%category' => $form_state['values']['title']), WATCHDOG_NOTICE, l(t('view'), 'admin/content/aggregator'));
drupal_set_message(t('The category %category has been added.', array('%category' => $form_state['values']['title'])));
}
}
......@@ -492,21 +492,21 @@ function aggregator_form_feed($edit = array('refresh' => 900, 'title' => '', 'ur
/**
* Validate aggregator_form_feed form submissions.
*/
function aggregator_form_feed_validate($form, &$form_state, $form_values) {
if ($form_values['op'] == t('Submit')) {
function aggregator_form_feed_validate($form, &$form_state) {
if ($form_state['values']['op'] == t('Submit')) {
// Check for duplicate titles
if (isset($form_values['fid'])) {
$result = db_query("SELECT title, url FROM {aggregator_feed} WHERE (title = '%s' OR url='%s') AND fid != %d", $form_values['title'], $form_values['url'], $form_values['fid']);
if (isset($form_state['values']['fid'])) {
$result = db_query("SELECT title, url FROM {aggregator_feed} WHERE (title = '%s' OR url='%s') AND fid != %d", $form_state['values']['title'], $form_state['values']['url'], $form_state['values']['fid']);
}
else {
$result = db_query("SELECT title, url FROM {aggregator_feed} WHERE title = '%s' OR url='%s'", $form_values['title'], $form_values['url']);
$result = db_query("SELECT title, url FROM {aggregator_feed} WHERE title = '%s' OR url='%s'", $form_state['values']['title'], $form_state['values']['url']);
}
while ($feed = db_fetch_object($result)) {
if (strcasecmp($feed->title, $form_values['title']) == 0) {
form_set_error('title', t('A feed named %feed already exists. Please enter a unique title.', array('%feed' => $form_values['title'])));
if (strcasecmp($feed->title, $form_state['values']['title']) == 0) {
form_set_error('title', t('A feed named %feed already exists. Please enter a unique title.', array('%feed' => $form_state['values']['title'])));
}
if (strcasecmp($feed->url, $form_values['url']) == 0) {
form_set_error('url', t('A feed with this URL %url already exists. Please enter a unique URL.', array('%url' => $form_values['url'])));
if (strcasecmp($feed->url, $form_state['values']['url']) == 0) {
form_set_error('url', t('A feed with this URL %url already exists. Please enter a unique URL.', array('%url' => $form_state['values']['url'])));
}
}
}
......@@ -516,23 +516,23 @@ function aggregator_form_feed_validate($form, &$form_state, $form_values) {
* Process aggregator_form_feed form submissions.
* @todo Add delete confirmation dialog.
*/
function aggregator_form_feed_submit($form, &$form_state, $form_values) {
if ($form_values['op'] == t('Delete')) {
$title = $form_values['title'];
function aggregator_form_feed_submit($form, &$form_state) {
if ($form_state['values']['op'] == t('Delete')) {
$title = $form_state['values']['title'];
// Unset the title:
unset($form_values['title']);
unset($form_state['values']['title']);
}
aggregator_save_feed($form_values);
aggregator_save_feed($form_state['values']);
menu_rebuild();
if (isset($form_values['fid'])) {
if (isset($form_values['title'])) {
drupal_set_message(t('The feed %feed has been updated.', array('%feed' => $form_values['title'])));
if (isset($form_state['values']['fid'])) {
if (isset($form_state['values']['title'])) {
drupal_set_message(t('The feed %feed has been updated.', array('%feed' => $form_state['values']['title'])));
if (arg(0) == 'admin') {
$form_state['redirect'] = 'admin/content/aggregator/';
return;
}
else {
$form_state['redirect'] = 'aggregator/sources/'. $form_values['fid'];
$form_state['redirect'] = 'aggregator/sources/'. $form_state['values']['fid'];
return;
}
}
......@@ -550,8 +550,8 @@ function aggregator_form_feed_submit($form, &$form_state, $form_values) {
}
}
else {
watchdog('aggregator', 'Feed %feed added.', array('%feed' => $form_values['title']), WATCHDOG_NOTICE, l(t('view'), 'admin/content/aggregator'));
drupal_set_message(t('The feed %feed has been added.', array('%feed' => $form_values['title'])));
watchdog('aggregator', 'Feed %feed added.', array('%feed' => $form_state['values']['title']), WATCHDOG_NOTICE, l(t('view'), 'admin/content/aggregator'));
drupal_set_message(t('The feed %feed has been added.', array('%feed' => $form_state['values']['title'])));
}
}
......@@ -1170,8 +1170,8 @@ function aggregator_page_list_validate($form_id, &$form) {
}
}
function aggregator_page_list_submit($form, &$form_state, $form_values) {
foreach ($form_values['categories'] as $iid => $selection) {
function aggregator_page_list_submit($form, &$form_state) {
foreach ($form_state['values']['categories'] as $iid => $selection) {
db_query('DELETE FROM {aggregator_category_item} WHERE iid = %d', $iid);
foreach ($selection as $cid) {
if ($cid) {
......
......@@ -292,8 +292,8 @@ function _block_compare($a, $b) {
/**
* Process main block administration form submission.
*/
function block_admin_display_submit($form, &$form_state, $form_values) {
foreach ($form_values as $block) {
function block_admin_display_submit($form, &$form_state) {
foreach ($form_state['values'] as $block) {
$block['status'] = $block['region'] != BLOCK_REGION_NONE;
$block['region'] = $block['status'] ? $block['region'] : '';
db_query("UPDATE {blocks} SET status = %d, weight = %d, region = '%s', throttle = %d WHERE module = '%s' AND delta = '%s' AND theme = '%s'", $block['status'], $block['weight'], $block['region'], isset($block['throttle']) ? $block['throttle'] : 0, $block['module'], $block['delta'], $block['theme']);
......@@ -498,22 +498,22 @@ function block_admin_configure($module = NULL, $delta = 0) {
return $form;
}
function block_admin_configure_validate($form, &$form_state, $form_values) {
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']))) {
function block_admin_configure_validate($form, &$form_state) {
if ($form_state['values']['module'] == 'block') {
if (empty($form_state['values']['info']) || db_num_rows(db_query("SELECT bid FROM {boxes} WHERE bid != %d AND info = '%s'", $form_state['values']['delta'], $form_state['values']['info']))) {
form_set_error('info', t('Please ensure that each block description is unique.'));
}
}
}
function block_admin_configure_submit($form, &$form_state, $form_values) {
function block_admin_configure_submit($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']);
foreach (array_filter($form_values['roles']) as $rid) {
db_query("INSERT INTO {blocks_roles} (rid, module, delta) VALUES (%d, '%s', '%s')", $rid, $form_values['module'], $form_values['delta']);
db_query("UPDATE {blocks} SET visibility = %d, pages = '%s', custom = %d, title = '%s' WHERE module = '%s' AND delta = '%s'", $form_state['values']['visibility'], trim($form_state['values']['pages']), $form_state['values']['custom'], $form_state['values']['title'], $form_state['values']['module'], $form_state['values']['delta']);
db_query("DELETE FROM {blocks_roles} WHERE module = '%s' AND delta = '%s'", $form_state['values']['module'], $form_state['values']['delta']);
foreach (array_filter($form_state['values']['roles']) as $rid) {
db_query("INSERT INTO {blocks_roles} (rid, module, delta) VALUES (%d, '%s', '%s')", $rid, $form_state['values']['module'], $form_state['values']['delta']);
}
module_invoke($form_values['module'], 'block', 'save', $form_values['delta'], $form_values);
module_invoke($form_state['values']['module'], 'block', 'save', $form_state['values']['delta'], $form_state['values']);
drupal_set_message(t('The block configuration has been saved.'));
cache_clear_all();
$form_state['redirect'] = 'admin/build/block';
......@@ -528,8 +528,8 @@ function block_add_block_form() {
return block_admin_configure('block', NULL);
}
function block_add_block_form_validate($form, &$form_state, $form_values) {
if (empty($form_values['info']) || db_num_rows(db_query("SELECT info FROM {boxes} WHERE info = '%s'", $form_values['info']))) {
function block_add_block_form_validate($form, &$form_state) {
if (empty($form_state['values']['info']) || db_num_rows(db_query("SELECT info FROM {boxes} WHERE info = '%s'", $form_state['values']['info']))) {
form_set_error('info', t('Please ensure that each block description is unique.'));
}
}
......@@ -537,20 +537,20 @@ function block_add_block_form_validate($form, &$form_state, $form_values) {
/**
* Save the new custom block.
*/
function block_add_block_form_submit($form, &$form_state, $form_values) {
function block_add_block_form_submit($form, &$form_state) {
$delta = db_next_id('{boxes}_bid');
foreach (list_themes() as $key => $theme) {
if ($theme->status) {
db_query("INSERT INTO {blocks} (visibility, pages, custom, title, module, theme, status, weight, delta) VALUES(%d, '%s', %d, '%s', '%s', '%s', %d, %d, %d)", $form_values['visibility'], trim($form_values['pages']), $form_values['custom'], $form_values['title'], $form_values['module'], $theme->name, 0, 0, $delta);
db_query("INSERT INTO {blocks} (visibility, pages, custom, title, module, theme, status, weight, delta) VALUES(%d, '%s', %d, '%s', '%s', '%s', %d, %d, %d)", $form_state['values']['visibility'], trim($form_state['values']['pages']), $form_state['values']['custom'], $form_state['values']['title'], $form_state['values']['module'], $theme->name, 0, 0, $delta);
}
}
foreach (array_filter($form_values['roles']) as $rid) {
db_query("INSERT INTO {blocks_roles} (rid, module, delta) VALUES (%d, '%s', '%s')", $rid, $form_values['module'], $delta);
foreach (array_filter($form_state['values']['roles']) as $rid) {
db_query("INSERT INTO {blocks_roles} (rid, module, delta) VALUES (%d, '%s', '%s')", $rid, $form_state['values']['module'], $delta);
}
db_query("INSERT INTO {boxes} (bid, body, info, format) VALUES (%d, '%s', '%s', %d)", $delta, $form_values['body'], $form_values['info'], $form_values['format']);
db_query("INSERT INTO {boxes} (bid, body, info, format) VALUES (%d, '%s', '%s', %d)", $delta, $form_state['values']['body'], $form_state['values']['info'], $form_state['values']['format']);
drupal_set_message(t('The block has been created.'));
cache_clear_all();
......@@ -573,10 +573,10 @@ function block_box_delete($bid = 0) {
/**
* Deletion of custom blocks.
*/
function block_box_delete_submit($form, &$form_state, $form_values) {
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'])));
function block_box_delete_submit($form, &$form_state) {
db_query('DELETE FROM {boxes} WHERE bid = %d', $form_state['values']['bid']);
db_query("DELETE FROM {blocks} WHERE module = 'block' AND delta = %d", $form_state['values']['bid']);
drupal_set_message(t('The block %name has been removed.', array('%name' => $form_state['values']['info'])));
cache_clear_all();
$form_state['redirect'] = 'admin/build/block';
return;
......
......@@ -260,7 +260,7 @@ function book_form(&$node) {
* Implementation of function book_outline()
* Handles all book outline operations.
*/
function book_outline($node) {
function book_outline($form_state, $node) {
$form['parent'] = array('#type' => 'select',
'#title' => t('Parent'),
'#default_value' => isset($node->parent) ? $node->parent : 0,
......@@ -298,19 +298,19 @@ function book_outline($node) {
/**
* Handles book outline form submissions.
*/
function book_outline_submit($form, &$form_state, $form_values) {
$op = $form_values['op'];
$node = node_load($form_values['nid']);
function book_outline_submit($form, &$form_state) {
$op = $form_state['values']['op'];
$node = node_load($form_state['values']['nid']);
switch ($op) {
case t('Add to book outline'):
db_query('INSERT INTO {book} (nid, vid, parent, weight) VALUES (%d, %d, %d, %d)', $node->nid, $node->vid, $form_values['parent'], $form_values['weight']);
db_query("UPDATE {node_revisions} SET log = '%s' WHERE vid = %d", $form_values['log'], $node->vid);
db_query('INSERT INTO {book} (nid, vid, parent, weight) VALUES (%d, %d, %d, %d)', $node->nid, $node->vid, $form_state['values']['parent'], $form_state['values']['weight']);
db_query("UPDATE {node_revisions} SET log = '%s' WHERE vid = %d", $form_state['values']['log'], $node->vid);
drupal_set_message(t('The post has been added to the book.'));
break;
case t('Update book outline'):
db_query('UPDATE {book} SET parent = %d, weight = %d WHERE vid = %d', $form_values['parent'], $form_values['weight'], $node->vid);
db_query("UPDATE {node_revisions} SET log = '%s' WHERE vid = %d", $form_values['log'], $node->vid);
db_query('UPDATE {book} SET parent = %d, weight = %d WHERE vid = %d', $form_state['values']['parent'], $form_state['values']['weight'], $node->vid);
db_query("UPDATE {node_revisions} SET log = '%s' WHERE vid = %d", $form_state['values']['log'], $node->vid);
drupal_set_message(t('The book outline has been updated.'));
break;
case t('Remove from book outline'):
......@@ -875,7 +875,7 @@ function theme_book_admin_table($form) {
/**
* Display an administrative view of the hierarchy of a book.
*/
function book_admin_edit($nid) {
function book_admin_edit($form_state, $nid) {
$node = node_load($nid);
if ($node->nid) {
drupal_set_title(check_plain($node->title));
......@@ -931,8 +931,8 @@ function book_admin_orphan() {
return $form;
}
function book_admin_edit_submit($form, &$form_state, $form_values) {