? sites/default/files ? sites/default/private ? sites/default/settings.php Index: modules/block/block.admin.inc =================================================================== RCS file: /cvs/drupal/drupal/modules/block/block.admin.inc,v retrieving revision 1.54 diff -u -p -r1.54 block.admin.inc --- modules/block/block.admin.inc 31 Aug 2009 17:06:08 -0000 1.54 +++ modules/block/block.admin.inc 1 Sep 2009 16:55:01 -0000 @@ -254,39 +254,37 @@ function block_admin_configure(&$form_st drupal_set_title(t("'%name' block", array('%name' => $info[$delta]['info'])), PASS_THROUGH); } + // Add JavaScript to hide the Pages field if the show always option is set. + drupal_add_js(drupal_get_path('module', 'block') . '/block.js'); + drupal_add_js(array('block' => array('visibilityPageAlways' => BLOCK_VISIBILITY_PAGE_ALWAYS)), 'setting'); + $form['page_vis_settings'] = array( '#type' => 'fieldset', '#title' => t('Page specific visibility settings'), '#collapsible' => TRUE, '#collapsed' => TRUE, ); + $form['page_vis_settings']['visibility'] = array( + '#type' => 'radios', + '#title' => t('Show this block'), + '#options' => array( + BLOCK_VISIBILITY_PAGE_ALWAYS => t('On every page.'), + BLOCK_VISIBILITY_PAGE_EXCLUDE => t('Except on specific pages.'), + BLOCK_VISIBILITY_PAGE_INCLUDE => t('On specific pages.'), + ), + '#default_value' => ($edit['visibility'] == BLOCK_VISIBILITY_PAGE_EXCLUDE && empty($edit['pages']) ? BLOCK_VISIBILITY_PAGE_ALWAYS : $edit['visibility']), + '#access' => user_access('use PHP for settings') || $edit['visibility'] != BLOCK_VISIBILITY_PAGE_PHP, + ); + $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.", array('%blog' => 'blog', '%blog-wildcard' => 'blog/*', '%front' => '')), + ); - $access = user_access('use PHP for settings'); - if ($edit['visibility'] == 2 && !$access) { - $form['page_vis_settings'] = array(); - $form['page_vis_settings']['visibility'] = array('#type' => 'value', '#value' => 2); - $form['page_vis_settings']['pages'] = array('#type' => 'value', '#value' => $edit['pages']); - } - else { - $options = array(t('Every page except those specified below.'), t('Only the pages specified below.')); - $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.", array('%blog' => 'blog', '%blog-wildcard' => 'blog/*', '%front' => '')); - - if (module_exists('php') && $access) { - $options[] = t('Show if the following PHP code returns TRUE (PHP-mode, experts only).'); - $description .= ' ' . t('If the PHP-mode is chosen, enter PHP code between %php. Note that executing incorrect PHP-code can break your Drupal site.', array('%php' => '')); - } - $form['page_vis_settings']['visibility'] = array( - '#type' => 'radios', - '#title' => t('Show block on specific pages'), - '#options' => $options, - '#default_value' => $edit['visibility'], - ); - $form['page_vis_settings']['pages'] = array( - '#type' => 'textarea', - '#title' => t('Pages'), - '#default_value' => $edit['pages'], - '#description' => $description, - ); + if (module_exists('php') && user_access('use PHP for settings')) { + $form['page_vis_settings']['visibility']['#options'][BLOCK_VISIBILITY_PAGE_PHP] = t('If the following PHP code returns TRUE (PHP-mode, experts only).'); + $form['page_vis_settings']['pages']['#description'] .= ' ' . t('If the PHP-mode is chosen, enter PHP code between %php. Note that executing incorrect PHP-code can break your Drupal site.', array('%php' => '')); } // Role-based visibility settings. @@ -367,8 +365,23 @@ function block_admin_configure_validate( } } +/** + * "Fix" the form_state's visibility and pages fields when adding or + * configuring a block. + */ +function _block_fix_form_state_visibility(&$form_state) { + // Don't actually store BLOCK_VISIBILITY_PAGE_ALWAYS in database; store + // "exclude nothing" instead + if ($form_state['values']['visibility'] == BLOCK_VISIBILITY_PAGE_ALWAYS) { + $form_state['values']['visibility'] = BLOCK_VISIBILITY_PAGE_EXCLUDE; + $form_state['values']['pages'] = ''; + } +} + function block_admin_configure_submit($form, &$form_state) { if (!form_get_errors()) { + _block_fix_form_state_visibility($form_state); + db_update('block') ->fields(array( 'visibility' => (int) $form_state['values']['visibility'], @@ -446,6 +459,8 @@ function block_add_block_form_validate($ * Save the new custom block. */ function block_add_block_form_submit($form, &$form_state) { + _block_fix_form_state_visibility($form_state); + $delta = db_insert('block_custom') ->fields(array( 'body' => $form_state['values']['body'], @@ -461,12 +476,12 @@ function block_add_block_form_submit($fo 'visibility' => (int) $form_state['values']['visibility'], 'pages' => trim($form_state['values']['pages']), 'custom' => (int) $form_state['values']['custom'], - 'title' => $form_state['values']['title'], + 'title' => $form_state['values']['title'], 'module' => $form_state['values']['module'], - 'theme' => $theme->name, + 'theme' => $theme->name, 'status' => 0, 'weight' => 0, - 'delta' => $delta, + 'delta' => $delta, 'cache' => DRUPAL_NO_CACHE, )); } Index: modules/block/block.js =================================================================== RCS file: /cvs/drupal/drupal/modules/block/block.js,v retrieving revision 1.11 diff -u -p -r1.11 block.js --- modules/block/block.js 31 Aug 2009 05:51:08 -0000 1.11 +++ modules/block/block.js 1 Sep 2009 16:55:01 -0000 @@ -10,6 +10,9 @@ Drupal.behaviors.blockDrag = { attach: function (context, settings) { var table = $('table#blocks'); + if (!table.size()) { + return; + } var tableDrag = Drupal.tableDrag.blocks; // Get the blocks tableDrag object. // Add a handler for when a row is swapped, update empty regions. @@ -106,4 +109,21 @@ Drupal.behaviors.blockDrag = { } }; +/** + * Show or hide the Pages element on the block configuration page based on + * whether the "On every page" setting is selected. If it's selected, hide + * the Pages element. + */ +Drupal.behaviors.blockVisibilitySettings = { + attach: function (context, settings) { + $("input[name='visibility']:not(.block-processed)", context).each(function () { + $(this).change(function (event) { + $('div.form-item-pages', context).toggle($(this).val() != Drupal.settings.block.visibilityPageAlways); + }); + $(this).addClass('block-processed'); + }); + $('div.form-item-pages', context).toggle($("input[name='visibility'][checked]").val() != Drupal.settings.block.visibilityPageAlways); + } +}; + })(jQuery); Index: modules/block/block.module =================================================================== RCS file: /cvs/drupal/drupal/modules/block/block.module,v retrieving revision 1.373 diff -u -p -r1.373 block.module --- modules/block/block.module 31 Aug 2009 17:06:08 -0000 1.373 +++ modules/block/block.module 1 Sep 2009 16:55:01 -0000 @@ -12,6 +12,16 @@ define('BLOCK_REGION_NONE', -1); /** + * Block visibility values. Only _EXCLUDE, _INCLUDE, _PHP are ever stored in + * the database; _ALWAYS is a user-interface value only, and is stored as + * _EXCLUDE with a blank "pages" field. + */ +define('BLOCK_VISIBILITY_PAGE_ALWAYS', 3); +define('BLOCK_VISIBILITY_PAGE_PHP', 2); +define('BLOCK_VISIBILITY_PAGE_EXCLUDE', 0); +define('BLOCK_VISIBILITY_PAGE_INCLUDE', 1); + +/** * Implement hook_help(). */ function block_help($path, $arg) { Index: modules/block/block.test =================================================================== RCS file: /cvs/drupal/drupal/modules/block/block.test,v retrieving revision 1.27 diff -u -p -r1.27 block.test --- modules/block/block.test 28 Aug 2009 19:44:05 -0000 1.27 +++ modules/block/block.test 1 Sep 2009 16:55:01 -0000 @@ -123,6 +123,7 @@ class BlockTestCase extends DrupalWebTes // Set the block to be hidden on any user path, and to be shown only to // authenticated users. $edit = array(); + $edit['visibility'] = '0'; // 'Except on specific pages.' $edit['pages'] = 'user*'; $edit['roles[2]'] = TRUE; $this->drupalPost('admin/structure/block/configure/' . $block['module'] . '/' . $block['delta'], $edit, t('Save block'));