From c8f6a2421b0b21dc14805ea262c3b8a97e77c9a5 Mon Sep 17 00:00:00 2001 From: Dries Buytaert <dries@buytaert.net> Date: Sun, 13 Nov 2005 08:26:01 +0000 Subject: [PATCH] - Patch #35524 by asimmonds / drewish: converted the custom block forms code to the forms API's execute model. --- modules/block.module | 192 +++++++++++++++++++------------------ modules/block/block.module | 192 +++++++++++++++++++------------------ 2 files changed, 200 insertions(+), 184 deletions(-) diff --git a/modules/block.module b/modules/block.module index c8175d61abb4..b7a4d98195d7 100644 --- a/modules/block.module +++ b/modules/block.module @@ -212,9 +212,18 @@ function _block_rehash($order_by = array('weight')) { * Prepare the main block administration form. */ function block_admin_display() { - global $theme_key; + global $theme_key, $custom_theme; $throttle = module_exist('throttle'); + // If non-default theme configuration has been selected, set the custom theme. + if (arg(3)) { + $custom_theme = arg(3); + } + else { + $custom_theme = variable_get('theme_default', 'bluemarine'); + } + init_theme(); + $blocks = _block_rehash(); $block_regions = system_region_list($theme_key); @@ -241,15 +250,9 @@ function block_admin_display() { } function theme_block_admin_display($form) { - - global $theme_key, $custom_theme; + global $theme_key; $throttle = module_exist('throttle'); - // If non-default theme configuration has been selected, set the custom theme. - if (arg(3)) { - $custom_theme = arg(3); - init_theme(); - } $block_regions = system_region_list($theme_key); // Highlight regions on page, to provide visual reference. @@ -312,76 +315,83 @@ function block_box_get($bid) { * Menu callback; displays the block configuration form. */ function block_admin_configure($module = NULL, $delta = 0) { - $edit = $_POST['edit']; - $op = $_POST['op']; - - switch ($op) { - case t('Save block'): - db_query("UPDATE {blocks} SET visibility = %d, pages = '%s', custom = %d WHERE module = '%s' AND delta = '%s'", $edit['visibility'], $edit['pages'], $edit['custom'], $module, $delta); - module_invoke($module, 'block', 'save', $delta, $edit); - drupal_set_message(t('The block configuration has been saved.')); - cache_clear_all(); - drupal_goto('admin/block'); - - default: - // Always evaluates to TRUE, but a validation step may be added later. - if (!$edit) { - $edit = db_fetch_array(db_query("SELECT pages, visibility, custom FROM {blocks} WHERE module = '%s' AND delta = '%s'", $module, $delta)); - } - // Module-specific block configurations. - if ($settings = module_invoke($module, 'block', 'configure', $delta)) { - $form['block_settings'] = array('#type' => 'fieldset', - '#title' => t('Block specific settings'), - '#collapsible' => true, - '#weight' => 0); + $form['module'] = array('#type' => 'value', '#value' => $module); + $form['delta'] = array('#type' => 'value', '#value' => $delta); - foreach ($settings as $k => $v) { - $form['block_settings'][$k] = $v; - } - } + $edit = db_fetch_array(db_query("SELECT pages, visibility, custom FROM {blocks} WHERE module = '%s' AND delta = '%s'", $module, $delta)); - // Get the block subject for the page title. - $info = module_invoke($module, 'block', 'list'); - drupal_set_title(t("'%name' block", array('%name' => $info[$delta]['info']))); + // Module-specific block configurations. + if ($settings = module_invoke($module, 'block', 'configure', $delta)) { + $form['block_settings'] = array( + '#type' => 'fieldset', + '#title' => t('Block specific settings'), + '#collapsible' => true, + '#weight' => 0, + ); - // Standard block configurations. - - $form['user_vis_settings'] = array('#type' => 'fieldset', - '#title' => t('User specific visibility settings'), - '#collapsible' => true, - '#weight' => 0); - - $form['user_vis_settings']['custom'] = array( - '#type' => 'radios', - '#title' => t('Custom visibility settings'), - '#default_value' => $edit['custom'], - '#options' => array(t('Users cannot control whether or not they see this block.'), t('Show this block by default, but let individual users hide it.'), t('Hide this block by default but let individual users show it.'), t('Allow individual users to customize the visibility of this block in their account settings.')), - '#default_value' => $edit['custom']); - - - $form['page_vis_settings'] = array('#type' => 'fieldset', - '#title' => t('Page specific visibility settings'), - '#collapsible' => true, - '#weight' => 0); - - - $form['page_vis_settings']['visibility'] = array( - '#type' => 'radios', - '#title' => t('Show block on specific pages'), - '#default_value' => $edit['visibility'], - '#options' => array(t('Show on every page except the listed pages.'), t('Show on only the listed pages.'), t('Show if the following PHP code returns <code>TRUE</code> (PHP-mode, experts only).')), - '#default_value' => $edit['visibility']); + foreach ($settings as $k => $v) { + $form['block_settings'][$k] = $v; + } + } - $form['page_vis_settings']['pages'] = array( - '#type' => 'textarea', - '#title' => t('Pages'), - '#default_value' => $edit['pages'], - '#description' => t("Enter one page per line as Drupal paths. The '*' character is a wildcard. Example paths are '%blog' for the blog page and %blog1 for every personal blog. %front is the front page. If the PHP-mode is chosen, enter PHP code between %php. Note that executing incorrect PHP-code can break your Drupal site.", array('%blog' => theme('placeholder', 'blog'), '%blog1' => theme('placeholder', 'blog/*'), '%front' => theme('placeholder', '<front>'), '%php' => theme('placeholder', '<?php ?>')))); + // Get the block subject for the page title. + $info = module_invoke($module, 'block', 'list'); + drupal_set_title(t("'%name' block", array('%name' => $info[$delta]['info']))); + + // Standard block configurations. + + $form['user_vis_settings'] = array( + '#type' => 'fieldset', + '#title' => t('User specific visibility settings'), + '#collapsible' => true, + '#weight' => 0, + ); + $form['user_vis_settings']['custom'] = array( + '#type' => 'radios', + '#title' => t('Custom visibility settings'), + '#options' => array(t('Users cannot control whether or not they see this block.'), t('Show this block by default, but let individual users hide it.'), t('Hide this block by default but let individual users show it.'), t('Allow individual users to customize the visibility of this block in their account settings.')), + '#default_value' => $edit['custom'], + ); + $form['page_vis_settings'] = array( + '#type' => 'fieldset', + '#title' => t('Page specific visibility settings'), + '#collapsible' => true, + '#weight' => 0, + ); + $form['page_vis_settings']['visibility'] = array( + '#type' => 'radios', + '#title' => t('Show block on specific pages'), + '#options' => array(t('Show on every page except the listed pages.'), t('Show on only the listed pages.'), t('Show if the following PHP code returns <code>TRUE</code> (PHP-mode, experts only).')), + '#default_value' => $edit['visibility'], + ); + $form['page_vis_settings']['pages'] = array( + '#type' => 'textarea', + '#title' => t('Pages'), + '#default_value' => $edit['pages'], + '#description' => t("Enter one page per line as Drupal paths. The '*' character is a wildcard. Example paths are '%blog' for the blog page and %blog-wildcard for every personal blog. %front is the front page. If the PHP-mode is chosen, enter PHP code between %php. Note that executing incorrect PHP-code can break your Drupal site.", array('%blog' => theme('placeholder', 'blog'), '%blog-wildcard' => theme('placeholder', 'blog/*'), '%front' => theme('placeholder', '<front>'), '%php' => theme('placeholder', '<?php ?>'))), + ); + $form['submit'] = array( + '#type' => 'submit', + '#value' => t('Save block'), + ); + + return drupal_get_form('block_admin_configure', $form); +} - $form['submit'] = array('#type' => 'submit', '#value' => t('Save block')); +function block_admin_configure_validate($form_id, $form_values) { + 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.')); + } +} - return drupal_get_form('block_config', $form); +function block_admin_configure_execute($form_id, $form_values) { + if (!form_get_errors()) { + db_query("UPDATE {blocks} SET visibility = %d, pages = '%s', custom = %d WHERE module = '%s' AND delta = '%s'", $form_values['visibility'], $form_values['pages'], $form_values['custom'], $form_values['module'], $form_values['delta']); + 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(); + drupal_goto('admin/block'); } } @@ -389,22 +399,25 @@ function block_admin_configure($module = NULL, $delta = 0) { * Menu callback; displays the block creation form. */ function block_box_add() { - $edit = $_POST['edit']; - $op = $_POST['op']; + $form = block_box_form(); + $form['submit'] = array('#type' => 'submit', '#value' => t('Save block')); - switch ($op) { - case t('Save block'): - if (block_box_save($edit)) { - drupal_set_message(t('The block has been created.')); - drupal_goto('admin/block'); - } - // deliberate no break - default: - $form = block_box_form($edit); - $form['submit'] = array('#type' => 'submit', '#value' => t('Save block')); + return drupal_get_form('block_box_add', $form); +} + +function block_box_add_validate($form_id, $form_values) { + 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.')); } +} - return drupal_get_form('block_box_add', $form); +function block_box_add_execute($form_id, $form_values) { + if (!form_get_errors()) { + if (block_box_save($form_values)) { + drupal_set_message(t('The block has been created.')); + drupal_goto('admin/block'); + } + } } /** @@ -421,10 +434,9 @@ function block_box_delete($bid = 0) { /** * Deletion of custom blocks. */ -function block_box_delete_confirm_execute($form_id, $edit) { - $form = $GLOBALS['form_values']; - db_query('DELETE FROM {boxes} WHERE bid = %d', $form['bid']); - drupal_set_message(t('The block %name has been removed.', array('%name' => theme('placeholder', $form['info'])))); +function block_box_delete_confirm_execute($form_id, $form_values) { + db_query('DELETE FROM {boxes} WHERE bid = %d', $form_values['bid']); + drupal_set_message(t('The block %name has been removed.', array('%name' => theme('placeholder', $form_values['info'])))); cache_clear_all(); drupal_goto('admin/block'); }; @@ -448,10 +460,6 @@ function block_box_save($edit, $delta = NULL) { db_query("UPDATE {boxes} SET title = '%s', body = '%s', info = '%s', format = %d WHERE bid = %d", $edit['title'], $edit['body'], $edit['info'], $edit['format'], $delta); } else { - if (empty($edit['info']) || db_num_rows(db_query("SELECT info FROM {boxes} WHERE info = '%s'", $edit['info']))) { - form_set_error('info', t('Please ensure that each block description is unique.')); - return false; - } db_query("INSERT INTO {boxes} (title, body, info, format) VALUES ('%s', '%s', '%s', %d)", $edit['title'], $edit['body'], $edit['info'], $edit['format']); } return true; diff --git a/modules/block/block.module b/modules/block/block.module index c8175d61abb4..b7a4d98195d7 100644 --- a/modules/block/block.module +++ b/modules/block/block.module @@ -212,9 +212,18 @@ function _block_rehash($order_by = array('weight')) { * Prepare the main block administration form. */ function block_admin_display() { - global $theme_key; + global $theme_key, $custom_theme; $throttle = module_exist('throttle'); + // If non-default theme configuration has been selected, set the custom theme. + if (arg(3)) { + $custom_theme = arg(3); + } + else { + $custom_theme = variable_get('theme_default', 'bluemarine'); + } + init_theme(); + $blocks = _block_rehash(); $block_regions = system_region_list($theme_key); @@ -241,15 +250,9 @@ function block_admin_display() { } function theme_block_admin_display($form) { - - global $theme_key, $custom_theme; + global $theme_key; $throttle = module_exist('throttle'); - // If non-default theme configuration has been selected, set the custom theme. - if (arg(3)) { - $custom_theme = arg(3); - init_theme(); - } $block_regions = system_region_list($theme_key); // Highlight regions on page, to provide visual reference. @@ -312,76 +315,83 @@ function block_box_get($bid) { * Menu callback; displays the block configuration form. */ function block_admin_configure($module = NULL, $delta = 0) { - $edit = $_POST['edit']; - $op = $_POST['op']; - - switch ($op) { - case t('Save block'): - db_query("UPDATE {blocks} SET visibility = %d, pages = '%s', custom = %d WHERE module = '%s' AND delta = '%s'", $edit['visibility'], $edit['pages'], $edit['custom'], $module, $delta); - module_invoke($module, 'block', 'save', $delta, $edit); - drupal_set_message(t('The block configuration has been saved.')); - cache_clear_all(); - drupal_goto('admin/block'); - - default: - // Always evaluates to TRUE, but a validation step may be added later. - if (!$edit) { - $edit = db_fetch_array(db_query("SELECT pages, visibility, custom FROM {blocks} WHERE module = '%s' AND delta = '%s'", $module, $delta)); - } - // Module-specific block configurations. - if ($settings = module_invoke($module, 'block', 'configure', $delta)) { - $form['block_settings'] = array('#type' => 'fieldset', - '#title' => t('Block specific settings'), - '#collapsible' => true, - '#weight' => 0); + $form['module'] = array('#type' => 'value', '#value' => $module); + $form['delta'] = array('#type' => 'value', '#value' => $delta); - foreach ($settings as $k => $v) { - $form['block_settings'][$k] = $v; - } - } + $edit = db_fetch_array(db_query("SELECT pages, visibility, custom FROM {blocks} WHERE module = '%s' AND delta = '%s'", $module, $delta)); - // Get the block subject for the page title. - $info = module_invoke($module, 'block', 'list'); - drupal_set_title(t("'%name' block", array('%name' => $info[$delta]['info']))); + // Module-specific block configurations. + if ($settings = module_invoke($module, 'block', 'configure', $delta)) { + $form['block_settings'] = array( + '#type' => 'fieldset', + '#title' => t('Block specific settings'), + '#collapsible' => true, + '#weight' => 0, + ); - // Standard block configurations. - - $form['user_vis_settings'] = array('#type' => 'fieldset', - '#title' => t('User specific visibility settings'), - '#collapsible' => true, - '#weight' => 0); - - $form['user_vis_settings']['custom'] = array( - '#type' => 'radios', - '#title' => t('Custom visibility settings'), - '#default_value' => $edit['custom'], - '#options' => array(t('Users cannot control whether or not they see this block.'), t('Show this block by default, but let individual users hide it.'), t('Hide this block by default but let individual users show it.'), t('Allow individual users to customize the visibility of this block in their account settings.')), - '#default_value' => $edit['custom']); - - - $form['page_vis_settings'] = array('#type' => 'fieldset', - '#title' => t('Page specific visibility settings'), - '#collapsible' => true, - '#weight' => 0); - - - $form['page_vis_settings']['visibility'] = array( - '#type' => 'radios', - '#title' => t('Show block on specific pages'), - '#default_value' => $edit['visibility'], - '#options' => array(t('Show on every page except the listed pages.'), t('Show on only the listed pages.'), t('Show if the following PHP code returns <code>TRUE</code> (PHP-mode, experts only).')), - '#default_value' => $edit['visibility']); + foreach ($settings as $k => $v) { + $form['block_settings'][$k] = $v; + } + } - $form['page_vis_settings']['pages'] = array( - '#type' => 'textarea', - '#title' => t('Pages'), - '#default_value' => $edit['pages'], - '#description' => t("Enter one page per line as Drupal paths. The '*' character is a wildcard. Example paths are '%blog' for the blog page and %blog1 for every personal blog. %front is the front page. If the PHP-mode is chosen, enter PHP code between %php. Note that executing incorrect PHP-code can break your Drupal site.", array('%blog' => theme('placeholder', 'blog'), '%blog1' => theme('placeholder', 'blog/*'), '%front' => theme('placeholder', '<front>'), '%php' => theme('placeholder', '<?php ?>')))); + // Get the block subject for the page title. + $info = module_invoke($module, 'block', 'list'); + drupal_set_title(t("'%name' block", array('%name' => $info[$delta]['info']))); + + // Standard block configurations. + + $form['user_vis_settings'] = array( + '#type' => 'fieldset', + '#title' => t('User specific visibility settings'), + '#collapsible' => true, + '#weight' => 0, + ); + $form['user_vis_settings']['custom'] = array( + '#type' => 'radios', + '#title' => t('Custom visibility settings'), + '#options' => array(t('Users cannot control whether or not they see this block.'), t('Show this block by default, but let individual users hide it.'), t('Hide this block by default but let individual users show it.'), t('Allow individual users to customize the visibility of this block in their account settings.')), + '#default_value' => $edit['custom'], + ); + $form['page_vis_settings'] = array( + '#type' => 'fieldset', + '#title' => t('Page specific visibility settings'), + '#collapsible' => true, + '#weight' => 0, + ); + $form['page_vis_settings']['visibility'] = array( + '#type' => 'radios', + '#title' => t('Show block on specific pages'), + '#options' => array(t('Show on every page except the listed pages.'), t('Show on only the listed pages.'), t('Show if the following PHP code returns <code>TRUE</code> (PHP-mode, experts only).')), + '#default_value' => $edit['visibility'], + ); + $form['page_vis_settings']['pages'] = array( + '#type' => 'textarea', + '#title' => t('Pages'), + '#default_value' => $edit['pages'], + '#description' => t("Enter one page per line as Drupal paths. The '*' character is a wildcard. Example paths are '%blog' for the blog page and %blog-wildcard for every personal blog. %front is the front page. If the PHP-mode is chosen, enter PHP code between %php. Note that executing incorrect PHP-code can break your Drupal site.", array('%blog' => theme('placeholder', 'blog'), '%blog-wildcard' => theme('placeholder', 'blog/*'), '%front' => theme('placeholder', '<front>'), '%php' => theme('placeholder', '<?php ?>'))), + ); + $form['submit'] = array( + '#type' => 'submit', + '#value' => t('Save block'), + ); + + return drupal_get_form('block_admin_configure', $form); +} - $form['submit'] = array('#type' => 'submit', '#value' => t('Save block')); +function block_admin_configure_validate($form_id, $form_values) { + 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.')); + } +} - return drupal_get_form('block_config', $form); +function block_admin_configure_execute($form_id, $form_values) { + if (!form_get_errors()) { + db_query("UPDATE {blocks} SET visibility = %d, pages = '%s', custom = %d WHERE module = '%s' AND delta = '%s'", $form_values['visibility'], $form_values['pages'], $form_values['custom'], $form_values['module'], $form_values['delta']); + 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(); + drupal_goto('admin/block'); } } @@ -389,22 +399,25 @@ function block_admin_configure($module = NULL, $delta = 0) { * Menu callback; displays the block creation form. */ function block_box_add() { - $edit = $_POST['edit']; - $op = $_POST['op']; + $form = block_box_form(); + $form['submit'] = array('#type' => 'submit', '#value' => t('Save block')); - switch ($op) { - case t('Save block'): - if (block_box_save($edit)) { - drupal_set_message(t('The block has been created.')); - drupal_goto('admin/block'); - } - // deliberate no break - default: - $form = block_box_form($edit); - $form['submit'] = array('#type' => 'submit', '#value' => t('Save block')); + return drupal_get_form('block_box_add', $form); +} + +function block_box_add_validate($form_id, $form_values) { + 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.')); } +} - return drupal_get_form('block_box_add', $form); +function block_box_add_execute($form_id, $form_values) { + if (!form_get_errors()) { + if (block_box_save($form_values)) { + drupal_set_message(t('The block has been created.')); + drupal_goto('admin/block'); + } + } } /** @@ -421,10 +434,9 @@ function block_box_delete($bid = 0) { /** * Deletion of custom blocks. */ -function block_box_delete_confirm_execute($form_id, $edit) { - $form = $GLOBALS['form_values']; - db_query('DELETE FROM {boxes} WHERE bid = %d', $form['bid']); - drupal_set_message(t('The block %name has been removed.', array('%name' => theme('placeholder', $form['info'])))); +function block_box_delete_confirm_execute($form_id, $form_values) { + db_query('DELETE FROM {boxes} WHERE bid = %d', $form_values['bid']); + drupal_set_message(t('The block %name has been removed.', array('%name' => theme('placeholder', $form_values['info'])))); cache_clear_all(); drupal_goto('admin/block'); }; @@ -448,10 +460,6 @@ function block_box_save($edit, $delta = NULL) { db_query("UPDATE {boxes} SET title = '%s', body = '%s', info = '%s', format = %d WHERE bid = %d", $edit['title'], $edit['body'], $edit['info'], $edit['format'], $delta); } else { - if (empty($edit['info']) || db_num_rows(db_query("SELECT info FROM {boxes} WHERE info = '%s'", $edit['info']))) { - form_set_error('info', t('Please ensure that each block description is unique.')); - return false; - } db_query("INSERT INTO {boxes} (title, body, info, format) VALUES ('%s', '%s', '%s', %d)", $edit['title'], $edit['body'], $edit['info'], $edit['format']); } return true; -- GitLab