diff options
author | Angie Byron <webchick@24967.no-reply.drupal.org> | 2010-11-22 06:12:39 +0000 |
---|---|---|
committer | Angie Byron <webchick@24967.no-reply.drupal.org> | 2010-11-22 06:12:39 +0000 |
commit | a61d3660236ac6bc3a39f413400bfebad24745c1 (patch) | |
tree | 2bbf6f0e8b65d24c0ec8a6408a26d06d67e3ab67 /modules/block | |
parent | bf2c1934b971e62d8a424928b86fb6785212df78 (diff) | |
download | brdo-a61d3660236ac6bc3a39f413400bfebad24745c1.tar.gz brdo-a61d3660236ac6bc3a39f413400bfebad24745c1.tar.bz2 |
#911290 by bspellmeyer: Fixed user-customizable block settings broken.
Diffstat (limited to 'modules/block')
-rw-r--r-- | modules/block/block.module | 15 | ||||
-rw-r--r-- | modules/block/block.test | 51 |
2 files changed, 63 insertions, 3 deletions
diff --git a/modules/block/block.module b/modules/block/block.module index 7f0f21070..72c3c5c56 100644 --- a/modules/block/block.module +++ b/modules/block/block.module @@ -559,7 +559,7 @@ function block_form_user_profile_form_alter(&$form, &$form_state) { $blocks[$block->module][$block->delta] = array( '#type' => 'checkbox', '#title' => check_plain($data[$block->delta]['info']), - '#default_value' => isset($account->block[$block->module][$block->delta]) ? $account->block[$block->module][$block->delta] : ($block->custom == 1), + '#default_value' => isset($account->data['block'][$block->module][$block->delta]) ? $account->data['block'][$block->module][$block->delta] : ($block->custom == 1), ); } } @@ -579,6 +579,15 @@ function block_form_user_profile_form_alter(&$form, &$form_state) { } /** + * Implements hook_user_presave(). + */ +function block_user_presave(&$edit, $account, $category) { + if (isset($edit['block'])) { + $edit['data']['block'] = $edit['block']; + } +} + +/** * Initialize blocks for enabled themes. */ function block_themes_enabled($theme_list) { @@ -741,8 +750,8 @@ function block_block_list_alter(&$blocks) { // Use the user's block visibility setting, if necessary. if ($block->custom != BLOCK_CUSTOM_FIXED) { - if ($user->uid && isset($user->block[$block->module][$block->delta])) { - $enabled = $user->block[$block->module][$block->delta]; + if ($user->uid && isset($user->data['block'][$block->module][$block->delta])) { + $enabled = $user->data['block'][$block->module][$block->delta]; } else { $enabled = ($block->custom == BLOCK_CUSTOM_ENABLED); diff --git a/modules/block/block.test b/modules/block/block.test index bb49fb57b..1a52cb23b 100644 --- a/modules/block/block.test +++ b/modules/block/block.test @@ -188,6 +188,57 @@ class BlockTestCase extends DrupalWebTestCase { } /** + * Test user customization of block visibility. + */ + function testBlockVisibilityPerUser() { + $block = array(); + + // Create a random title for the block. + $title = $this->randomName(8); + + // Create our custom test block. + $custom_block = array(); + $custom_block['info'] = $this->randomName(8); + $custom_block['title'] = $title; + $custom_block['body[value]'] = $this->randomName(32); + $this->drupalPost('admin/structure/block/add', $custom_block, t('Save block')); + + $bid = db_query("SELECT bid FROM {block_custom} WHERE info = :info", array(':info' => $custom_block['info']))->fetchField(); + $block['module'] = 'block'; + $block['delta'] = $bid; + $block['title'] = $title; + + // Move block to the first sidebar. + $this->moveBlockToRegion($block, $this->regions[1]); + + // Set the block to be customizable per user, visible by default. + $edit = array(); + $edit['custom'] = BLOCK_CUSTOM_ENABLED; + $this->drupalPost('admin/structure/block/manage/' . $block['module'] . '/' . $block['delta'] . '/configure', $edit, t('Save block')); + + // Disable block visibility for the admin user. + $edit = array(); + $edit['block[' . $block['module'] . '][' . $block['delta'] . ']'] = FALSE; + $this->drupalPost('user/' . $this->admin_user->uid . '/edit', $edit, t('Save')); + + $this->drupalGet(''); + $this->assertNoText($block['title'], t('Block was not displayed according to per user block visibility setting.')); + + // Set the block to be customizable per user, hidden by default. + $edit = array(); + $edit['custom'] = BLOCK_CUSTOM_DISABLED; + $this->drupalPost('admin/structure/block/manage/' . $block['module'] . '/' . $block['delta'] . '/configure', $edit, t('Save block')); + + // Enable block visibility for the admin user. + $edit = array(); + $edit['block[' . $block['module'] . '][' . $block['delta'] . ']'] = TRUE; + $this->drupalPost('user/' . $this->admin_user->uid . '/edit', $edit, t('Save')); + + $this->drupalGet(''); + $this->assertText($block['title'], t('Block was displayed according to per user block visibility setting.')); + } + + /** * Test configuring and moving a module-define block to specific regions. */ function testBlock() { |