' : $_GET['q'];
$languages = language_list('enabled');
$links = array();
diff --git a/modules/menu/menu.module b/modules/menu/menu.module
index 656a87a8a0d93796c0c9e71df4df3a4bf3fab392..64190c63782139ea25ad1a92d31b7f3f486c50db 100644
--- a/modules/menu/menu.module
+++ b/modules/menu/menu.module
@@ -257,28 +257,35 @@ function menu_reset_item($item) {
}
/**
- * Implementation of hook_block().
+ * Implementation of hook_block_list().
*/
-function menu_block($op = 'list', $delta = '') {
+function menu_block_list() {
$menus = menu_get_menus();
// The Navigation menu is handled by the user module.
unset($menus['navigation']);
- if ($op == 'list') {
- $blocks = array();
- foreach ($menus as $name => $title) {
- // Default "Navigation" block is handled by user.module.
- $blocks[$name]['info'] = check_plain($title);
- // Menu blocks can't be cached because each menu item can have
- // a custom access callback. menu.inc manages its own caching.
- $blocks[$name]['cache'] = BLOCK_NO_CACHE;
- }
- return $blocks;
- }
- elseif ($op == 'view') {
- $data['subject'] = check_plain($menus[$delta]);
- $data['content'] = menu_tree($delta);
- return $data;
+
+ $blocks = array();
+ foreach ($menus as $name => $title) {
+ // Default "Navigation" block is handled by user.module.
+ $blocks[$name]['info'] = check_plain($title);
+ // Menu blocks can't be cached because each menu item can have
+ // a custom access callback. menu.inc manages its own caching.
+ $blocks[$name]['cache'] = BLOCK_NO_CACHE;
}
+ return $blocks;
+}
+
+/**
+ * Implementation of hook_block_view().
+ */
+function menu_block_view($delta = '') {
+ $menus = menu_get_menus();
+ // The Navigation menu is handled by the user module.
+ unset($menus['navigation']);
+
+ $data['subject'] = check_plain($menus[$delta]);
+ $data['content'] = menu_tree($delta);
+ return $data;
}
/**
diff --git a/modules/node/node.module b/modules/node/node.module
index 27ff4be3f89ffdb2b099f9eee2d478853b1a3acf..c657a1548a00118eaebd724d225fbcbcb640f9bd 100644
--- a/modules/node/node.module
+++ b/modules/node/node.module
@@ -1779,21 +1779,23 @@ function node_revision_list($node) {
}
/**
- * Implementation of hook_block().
+ * Implementation of hook_block_list().
*/
-function node_block($op = 'list', $delta = '') {
- if ($op == 'list') {
- $blocks['syndicate']['info'] = t('Syndicate');
- // Not worth caching.
- $blocks['syndicate']['cache'] = BLOCK_NO_CACHE;
- return $blocks;
- }
- elseif ($op == 'view') {
- $block['subject'] = t('Syndicate');
- $block['content'] = theme('feed_icon', url('rss.xml'), t('Syndicate'));
+function node_block_list() {
+ $blocks['syndicate']['info'] = t('Syndicate');
+ // Not worth caching.
+ $blocks['syndicate']['cache'] = BLOCK_NO_CACHE;
+ return $blocks;
+}
- return $block;
- }
+/**
+ * Implementation of hook_block_view().
+ */
+function node_block_view($delta = '') {
+ $block['subject'] = t('Syndicate');
+ $block['content'] = theme('feed_icon', url('rss.xml'), t('Syndicate'));
+
+ return $block;
}
/**
diff --git a/modules/node/node.test b/modules/node/node.test
index 2e8a94d92d46ca09110be1ab9672b13fad8798e8..ab2a25f87e1285a3814a3f9d09426c327a0cf3c5 100644
--- a/modules/node/node.test
+++ b/modules/node/node.test
@@ -507,3 +507,33 @@ class NodeTitleXSSTestCase extends DrupalWebTestCase {
$this->assertNoRaw($xss, t('Harmful tags are escaped when editing a node.'));
}
}
+
+class NodeBlockTestCase extends DrupalWebTestCase {
+ function getInfo() {
+ return array(
+ 'name' => t('Block availability'),
+ 'description' => t('Check if the syndicate block is available.'),
+ 'group' => t('Node'),
+ );
+ }
+
+ function setUp() {
+ parent::setUp();
+
+ // Create and login user
+ $admin_user = $this->drupalCreateUser(array('administer blocks'));
+ $this->drupalLogin($admin_user);
+ }
+
+ function testSearchFormBlock() {
+ // Set block title to confirm that the interface is availble.
+ $this->drupalPost('admin/build/block/configure/node/syndicate', array('title' => $this->randomName(8)), t('Save block'));
+ $this->assertText(t('The block configuration has been saved.'), t('Block configuration set.'));
+
+ // Set the block to a region to confirm block is availble.
+ $edit = array();
+ $edit['node_syndicate[region]'] = 'footer';
+ $this->drupalPost('admin/build/block', $edit, t('Save blocks'));
+ $this->assertText(t('The block settings have been updated.'), t('Block successfully move to footer region.'));
+ }
+}
diff --git a/modules/poll/poll.module b/modules/poll/poll.module
index cd7d4947465adb657d2ff2119b26f6ac947bc764..f31ac634d7ad3c3825fc33b209175e2d97f5e77f 100644
--- a/modules/poll/poll.module
+++ b/modules/poll/poll.module
@@ -136,29 +136,33 @@ function _poll_menu_access($node, $perm, $inspect_allowvotes) {
}
/**
- * Implementation of hook_block().
+ * Implementation of hook_block_list().
+ */
+function poll_block_list() {
+ if (user_access('access content')) {
+ $blocks['recent']['info'] = t('Most recent poll');
+ return $blocks;
+ }
+}
+
+/**
+ * Implementation of hook_block_view().
*
* Generates a block containing the latest poll.
*/
-function poll_block($op = 'list', $delta = '') {
+function poll_block_view($delta = '') {
if (user_access('access content')) {
- if ($op == 'list') {
- $blocks['recent']['info'] = t('Most recent poll');
- return $blocks;
- }
- elseif ($op == 'view') {
- // Retrieve the latest poll.
- $record = db_query_range(db_rewrite_sql("SELECT n.nid FROM {node} n INNER JOIN {poll} p ON p.nid = n.nid WHERE n.status = :status AND p.active = :active ORDER BY n.created DESC"), array(':status' => 1, ':active' => 1), 0, 1)->fetch();
- if ($record) {
- $poll = node_load($record->nid);
- if ($poll->nid) {
- $poll = poll_view($poll, TRUE, FALSE, TRUE);
- }
+ // Retrieve the latest poll.
+ $record = db_query_range(db_rewrite_sql("SELECT n.nid FROM {node} n INNER JOIN {poll} p ON p.nid = n.nid WHERE n.status = :status AND p.active = :active ORDER BY n.created DESC"), array(':status' => 1, ':active' => 1), 0, 1)->fetch();
+ if ($record) {
+ $poll = node_load($record->nid);
+ if ($poll->nid) {
+ $poll = poll_view($poll, TRUE, FALSE, TRUE);
}
- $block['subject'] = t('Poll');
- $block['content'] = drupal_render($poll->content);
- return $block;
}
+ $block['subject'] = t('Poll');
+ $block['content'] = drupal_render($poll->content);
+ return $block;
}
}
diff --git a/modules/poll/poll.test b/modules/poll/poll.test
index 83ac6177896d62beaef82bbeef949da959f1c4e9..a7030db3fc662bc1a5f81f5e69de1f5e5094acd5 100644
--- a/modules/poll/poll.test
+++ b/modules/poll/poll.test
@@ -124,3 +124,32 @@ class PollVoteTestCase extends PollTestCase {
}
}
+class PollBlockTestCase extends DrupalWebTestCase {
+ function getInfo() {
+ return array(
+ 'name' => t('Block availability'),
+ 'description' => t('Check if the most recent poll block is available.'),
+ 'group' => t('Poll'),
+ );
+ }
+
+ function setUp() {
+ parent::setUp('poll');
+
+ // Create and login user
+ $admin_user = $this->drupalCreateUser(array('administer blocks'));
+ $this->drupalLogin($admin_user);
+ }
+
+ function testRecentBlock() {
+ // Set block title to confirm that the interface is availble.
+ $this->drupalPost('admin/build/block/configure/poll/recent', array('title' => $this->randomName(8)), t('Save block'));
+ $this->assertText(t('The block configuration has been saved.'), t('Block configuration set.'));
+
+ // Set the block to a region to confirm block is availble.
+ $edit = array();
+ $edit['poll_recent[region]'] = 'footer';
+ $this->drupalPost('admin/build/block', $edit, t('Save blocks'));
+ $this->assertText(t('The block settings have been updated.'), t('Block successfully move to footer region.'));
+ }
+}
diff --git a/modules/profile/profile.module b/modules/profile/profile.module
index 6ecd27c67994e5ba8350ea265bb79f8f87f9d5f2..a028800f7221d24f50d9a42bfeb12b19747c9fe6 100644
--- a/modules/profile/profile.module
+++ b/modules/profile/profile.module
@@ -126,70 +126,79 @@ function profile_menu() {
}
/**
- * Implementation of hook_block().
+ * Implementation of hook_block_list().
*/
-function profile_block($op = 'list', $delta = '', $edit = array()) {
+function profile_block_list() {
+ $blocks['author-information']['info'] = t('Author information');
+ $blocks['author-information']['cache'] = BLOCK_CACHE_PER_PAGE | BLOCK_CACHE_PER_ROLE;
+ return $blocks;
+}
- if ($op == 'list') {
- $blocks['author-information']['info'] = t('Author information');
- $blocks['author-information']['cache'] = BLOCK_CACHE_PER_PAGE | BLOCK_CACHE_PER_ROLE;
- return $blocks;
- }
- elseif ($op == 'configure') {
- // Compile a list of fields to show
- $fields = array();
- $result = db_query('SELECT name, title, weight, visibility FROM {profile_field} WHERE visibility IN (%d, %d) ORDER BY weight', PROFILE_PUBLIC, PROFILE_PUBLIC_LISTINGS);
- while ($record = db_fetch_object($result)) {
- $fields[$record->name] = check_plain($record->title);
- }
- $fields['user_profile'] = t('Link to full user profile');
- $form['profile_block_author_fields'] = array(
- '#type' => 'checkboxes',
- '#title' => t('Profile fields to display'),
- '#default_value' => variable_get('profile_block_author_fields', array()),
- '#options' => $fields,
- '#description' => t('Select which profile fields you wish to display in the block. Only fields designated as public in the profile field configuration are available.', array('@profile-admin' => url('admin/user/profile'))),
- );
- return $form;
- }
- elseif ($op == 'save') {
- variable_set('profile_block_author_fields', $edit['profile_block_author_fields']);
+/**
+ * Implementation of hook_block_configure().
+ */
+function profile_block_configure($delta = '') {
+ // Compile a list of fields to show
+ $fields = array();
+ $result = db_query('SELECT name, title, weight, visibility FROM {profile_field} WHERE visibility IN (%d, %d) ORDER BY weight', PROFILE_PUBLIC, PROFILE_PUBLIC_LISTINGS);
+ while ($record = db_fetch_object($result)) {
+ $fields[$record->name] = check_plain($record->title);
}
- elseif ($op == 'view') {
- if (user_access('access user profiles')) {
- $output = '';
- if ((arg(0) == 'node') && is_numeric(arg(1)) && (arg(2) == NULL)) {
- $node = node_load(arg(1));
- $account = user_load(array('uid' => $node->uid));
-
- if ($use_fields = variable_get('profile_block_author_fields', array())) {
- // Compile a list of fields to show.
- $fields = array();
- $result = db_query('SELECT name, title, type, visibility, weight FROM {profile_field} WHERE visibility IN (%d, %d) ORDER BY weight', PROFILE_PUBLIC, PROFILE_PUBLIC_LISTINGS);
- while ($record = db_fetch_object($result)) {
- // Ensure that field is displayed only if it is among the defined block fields and, if it is private, the user has appropriate permissions.
- if (isset($use_fields[$record->name]) && $use_fields[$record->name]) {
- $fields[] = $record;
- }
- }
- }
+ $fields['user_profile'] = t('Link to full user profile');
+ $form['profile_block_author_fields'] = array(
+ '#type' => 'checkboxes',
+ '#title' => t('Profile fields to display'),
+ '#default_value' => variable_get('profile_block_author_fields', array()),
+ '#options' => $fields,
+ '#description' => t('Select which profile fields you wish to display in the block. Only fields designated as public in the profile field configuration are available.', array('@profile-admin' => url('admin/user/profile'))),
+ );
+ return $form;
+}
- if (!empty($fields)) {
- $profile = _profile_update_user_fields($fields, $account);
- $output .= theme('profile_block', $account, $profile, TRUE);
- }
+/**
+ * Implementation of hook_block_save().
+ */
+function profile_block_save($delta = '', $edit = array()) {
+ variable_set('profile_block_author_fields', $edit['profile_block_author_fields']);
+}
- if (isset($use_fields['user_profile']) && $use_fields['user_profile']) {
- $output .= '' . l(t('View full user profile'), 'user/' . $account->uid) . '
';
+/**
+ * Implementation of hook_block_view().
+ */
+function profile_block_view($delta = '') {
+ if (user_access('access user profiles')) {
+ $output = '';
+ if ((arg(0) == 'node') && is_numeric(arg(1)) && (arg(2) == NULL)) {
+ $node = node_load(arg(1));
+ $account = user_load(array('uid' => $node->uid));
+
+ if ($use_fields = variable_get('profile_block_author_fields', array())) {
+ // Compile a list of fields to show.
+ $fields = array();
+ $result = db_query('SELECT name, title, type, visibility, weight FROM {profile_field} WHERE visibility IN (%d, %d) ORDER BY weight', PROFILE_PUBLIC, PROFILE_PUBLIC_LISTINGS);
+ while ($record = db_fetch_object($result)) {
+ // Ensure that field is displayed only if it is among the defined block fields and, if it is private, the user has appropriate permissions.
+ if (isset($use_fields[$record->name]) && $use_fields[$record->name]) {
+ $fields[] = $record;
+ }
}
}
- if ($output) {
- $block['subject'] = t('About %name', array('%name' => $account->name));
- $block['content'] = $output;
- return $block;
+ if (!empty($fields)) {
+ $profile = _profile_update_user_fields($fields, $account);
+ $output .= theme('profile_block', $account, $profile, TRUE);
+ }
+
+ if (isset($use_fields['user_profile']) && $use_fields['user_profile']) {
+ $output .= '' . l(t('View full user profile'), 'user/' . $account->uid) . '
';
}
}
+
+ if ($output) {
+ $block['subject'] = t('About %name', array('%name' => $account->name));
+ $block['content'] = $output;
+ return $block;
+ }
}
}
diff --git a/modules/profile/profile.test b/modules/profile/profile.test
index 7dd22c043d7118650662d5c64f2d5c15adb2b3d5..8b17c07a4bad2f918a0a2c315bd262bbd8383b90 100644
--- a/modules/profile/profile.test
+++ b/modules/profile/profile.test
@@ -289,6 +289,36 @@ class ProfileTestAutocomplete extends ProfileTestCase {
}
}
+class ProfileBlockTestCase extends DrupalWebTestCase {
+ function getInfo() {
+ return array(
+ 'name' => t('Block availability'),
+ 'description' => t('Check if the author-information block is available.'),
+ 'group' => t('Profile'),
+ );
+ }
+
+ function setUp() {
+ parent::setUp('profile');
+
+ // Create and login user
+ $admin_user = $this->drupalCreateUser(array('administer blocks'));
+ $this->drupalLogin($admin_user);
+ }
+
+ function testAuthorInformationBlock() {
+ // Set block title to confirm that the interface is availble.
+ $this->drupalPost('admin/build/block/configure/profile/author-information', array('title' => $this->randomName(8)), t('Save block'));
+ $this->assertText(t('The block configuration has been saved.'), t('Block configuration set.'));
+
+ // Set the block to a region to confirm block is availble.
+ $edit = array();
+ $edit['profile_author-information[region]'] = 'footer';
+ $this->drupalPost('admin/build/block', $edit, t('Save blocks'));
+ $this->assertText(t('The block settings have been updated.'), t('Block successfully move to footer region.'));
+ }
+}
+
/**
* TODO:
* - Test field visibility
diff --git a/modules/search/search.module b/modules/search/search.module
index 8bb5a74d30ed45c6bc8793e9a16e46f9d848ff59..8c3f496cacd066f6b6bad105c114cc8137af9b40 100644
--- a/modules/search/search.module
+++ b/modules/search/search.module
@@ -158,16 +158,20 @@ function search_perm() {
}
/**
- * Implementation of hook_block().
+ * Implementation of hook_block_list().
*/
-function search_block($op = 'list', $delta = '') {
- if ($op == 'list') {
- $blocks['form']['info'] = t('Search form');
- // Not worth caching.
- $blocks['form']['cache'] = BLOCK_NO_CACHE;
- return $blocks;
- }
- elseif ($op == 'view' && user_access('search content')) {
+function search_block_list() {
+ $blocks['form']['info'] = t('Search form');
+ // Not worth caching.
+ $blocks['form']['cache'] = BLOCK_NO_CACHE;
+ return $blocks;
+}
+
+/**
+ * Implementation of hook_block_view().
+ */
+function search_block_view($delta = '') {
+ if (user_access('search content')) {
$block['content'] = drupal_get_form('search_block_form');
$block['subject'] = t('Search');
return $block;
diff --git a/modules/search/search.test b/modules/search/search.test
index a99d1e00d1945c5eb3a9bd89adc2c3e53540ddd4..c7f9ecc779fcff02cdd0be9e54bb4673dec0fdba 100644
--- a/modules/search/search.test
+++ b/modules/search/search.test
@@ -333,3 +333,33 @@ class SearchRankingTestCase extends DrupalWebTestCase {
}
}
}
+
+class SearchBlockTestCase extends DrupalWebTestCase {
+ function getInfo() {
+ return array(
+ 'name' => t('Block availability'),
+ 'description' => t('Check if the search form block is available.'),
+ 'group' => t('Search'),
+ );
+ }
+
+ function setUp() {
+ parent::setUp('search');
+
+ // Create and login user
+ $admin_user = $this->drupalCreateUser(array('administer blocks'));
+ $this->drupalLogin($admin_user);
+ }
+
+ function testSearchFormBlock() {
+ // Set block title to confirm that the interface is availble.
+ $this->drupalPost('admin/build/block/configure/search/form', array('title' => $this->randomName(8)), t('Save block'));
+ $this->assertText(t('The block configuration has been saved.'), t('Block configuration set.'));
+
+ // Set the block to a region to confirm block is availble.
+ $edit = array();
+ $edit['search_form[region]'] = 'footer';
+ $this->drupalPost('admin/build/block', $edit, t('Save blocks'));
+ $this->assertText(t('The block settings have been updated.'), t('Block successfully move to footer region.'));
+ }
+}
diff --git a/modules/system/system.module b/modules/system/system.module
index 8046f10ad6654ad9240c6631f37792ef2434c698..ad56aea37892912a6ed05c329cd7e3a5eb6d40fa 100644
--- a/modules/system/system.module
+++ b/modules/system/system.module
@@ -836,51 +836,65 @@ function system_user_timezone(&$edit, &$form) {
}
/**
- * Implementation of hook_block().
+ * Implementation of hook_block_list().
+ */
+function system_block_list() {
+ $image_path = 'misc/' . variable_get('drupal_badge_color', 'powered-blue') . '-' . variable_get('drupal_badge_size', '80x15') . '.png';
+ $blocks['powered-by'] = array(
+ 'info' => t('Powered by Drupal'),
+ 'weight' => '10',
+ // Not worth caching.
+ 'cache' => BLOCK_NO_CACHE,
+ );
+ return $blocks;
+}
+
+/**
+ * Implementation of hook_block_configure().
+ */
+function system_block_configure($delta = '') {
+ $image_path = 'misc/' . variable_get('drupal_badge_color', 'powered-blue') . '-' . variable_get('drupal_badge_size', '80x15') . '.png';
+ drupal_add_js(drupal_get_path('module', 'system') .'/system.js');
+ // Compile a list of fields to show
+ $form['wrapper']['color'] = array(
+ '#type' => 'select',
+ '#title' => t('Badge color'),
+ '#default_value' => variable_get('drupal_badge_color', 'powered-blue'),
+ '#options' => array('powered-black' => t('Black'), 'powered-blue' => t('Blue'), 'powered-gray' => t('Gray')),
+ );
+ $form['wrapper']['size'] = array(
+ '#type' => 'select',
+ '#title' => t('Badge size'),
+ '#default_value' => variable_get('drupal_badge_size', '80x15'),
+ '#options' => array('80x15' => t('Small'), '88x31' => t('Medium'), '135x42' => t('Large')),
+ );
+ $form['wrapper']['preview'] = array(
+ '#type' => 'item',
+ '#title' => 'Preview',
+ '#markup' => theme('image', $image_path, t('Powered by Drupal, an open source content management system'), t('Powered by Drupal, an open source content management system'), array('class' => 'powered-by-preview'), FALSE),
+ );
+ return $form;
+}
+
+/**
+ * Implementation of hook_block_save().
+ */
+function system_block_save($delta = '', $edit = NULL) {
+ $image_path = 'misc/' . variable_get('drupal_badge_color', 'powered-blue') . '-' . variable_get('drupal_badge_size', '80x15') . '.png';
+ variable_set('drupal_badge_color', $edit['color']);
+ variable_set('drupal_badge_size', $edit['size']);
+}
+
+/**
+ * Implementation of hook_block_view().
*
* Generate a block with a promotional link to Drupal.org.
*/
-function system_block($op = 'list', $delta = '', $edit = NULL) {
+function system_block_view($delta = '') {
$image_path = 'misc/' . variable_get('drupal_badge_color', 'powered-blue') . '-' . variable_get('drupal_badge_size', '80x15') . '.png';
- switch ($op) {
- case 'list':
- $blocks['powered-by'] = array(
- 'info' => t('Powered by Drupal'),
- 'weight' => '10',
- // Not worth caching.
- 'cache' => BLOCK_NO_CACHE,
- );
- return $blocks;
- case 'configure':
- drupal_add_js(drupal_get_path('module', 'system') .'/system.js');
- // Compile a list of fields to show
- $form['wrapper']['color'] = array(
- '#type' => 'select',
- '#title' => t('Badge color'),
- '#default_value' => variable_get('drupal_badge_color', 'powered-blue'),
- '#options' => array('powered-black' => t('Black'), 'powered-blue' => t('Blue'), 'powered-gray' => t('Gray')),
- );
- $form['wrapper']['size'] = array(
- '#type' => 'select',
- '#title' => t('Badge size'),
- '#default_value' => variable_get('drupal_badge_size', '80x15'),
- '#options' => array('80x15' => t('Small'), '88x31' => t('Medium'), '135x42' => t('Large')),
- );
- $form['wrapper']['preview'] = array(
- '#type' => 'item',
- '#title' => 'Preview',
- '#markup' => theme('image', $image_path, t('Powered by Drupal, an open source content management system'), t('Powered by Drupal, an open source content management system'), array('class' => 'powered-by-preview'), FALSE),
- );
- return $form;
- case 'save':
- variable_set('drupal_badge_color', $edit['color']);
- variable_set('drupal_badge_size', $edit['size']);
- break;
- case 'view':
- $block['subject'] = NULL; // Don't display a title
- $block['content'] = theme('system_powered_by', $image_path);
- return $block;
- }
+ $block['subject'] = NULL; // Don't display a title
+ $block['content'] = theme('system_powered_by', $image_path);
+ return $block;
}
/**
diff --git a/modules/system/system.test b/modules/system/system.test
index 9b1b2cbdc344848da31b24dbe5d87122011f6891..f07d8707e07e2b79024d44110f4e3920800bb851 100644
--- a/modules/system/system.test
+++ b/modules/system/system.test
@@ -631,3 +631,55 @@ class FrontPageTestCase extends DrupalWebTestCase {
$this->assertText(t('On front page.'), t('Path is the front page.'));
}
}
+
+class SystemBlockTestCase extends DrupalWebTestCase {
+ function getInfo() {
+ return array(
+ 'name' => t('Block functionality'),
+ 'description' => t('Configure and move powered-by block.'),
+ 'group' => t('System'),
+ );
+ }
+
+ function setUp() {
+ parent::setUp();
+
+ // Create and login user
+ $admin_user = $this->drupalCreateUser(array('administer blocks'));
+ $this->drupalLogin($admin_user);
+ }
+
+ /**
+ * Test displaying and hiding the powered-by block.
+ */
+ function testPoweredByBlock() {
+ // Set block title and some settings to confirm that the interface is availble.
+ $this->drupalPost('admin/build/block/configure/system/powered-by', array('title' => $this->randomName(8), 'color' => 'powered-black', 'size' => '135x42'), t('Save block'));
+ $this->assertText(t('The block configuration has been saved.'), t('Block configuration set.'));
+
+ // Set the powered-by block to the footer region.
+ $edit = array();
+ $edit['system_powered-by[region]'] = 'footer';
+ $this->drupalPost('admin/build/block', $edit, t('Save blocks'));
+ $this->assertText(t('The block settings have been updated.'), t('Block successfully move to footer region.'));
+
+ // Confirm that the block is being displayed.
+ $this->assertRaw('id="block-system-powered-by"', t('Block successfully being displayed on the page.'));
+
+ // Set the block to the disabled region.
+ $edit = array();
+ $edit['system_powered-by[region]'] = '-1';
+ $this->drupalPost('admin/build/block', $edit, t('Save blocks'));
+
+ // Confirm that the block is hidden.
+ $this->assertNoRaw('id="block-system-powered-by"', t('Block no longer appears on page.'));
+
+ // For convenience of developers, set the block to it's default settings.
+ $edit = array();
+ $edit['system_powered-by[region]'] = 'footer';
+ $this->drupalPost('admin/build/block', $edit, t('Save blocks'));
+ $this->drupalPost('admin/build/block/configure/system/powered-by', array('title' => '', 'color' => 'powered-blue', 'size' => '80x15'), t('Save block'));
+ }
+
+}
+
diff --git a/modules/user/user.module b/modules/user/user.module
index 464ac755b4558766fd8e07d0041011642bc2a171..bb4df163451f1f03be743a14e6f7df404851af01 100644
--- a/modules/user/user.module
+++ b/modules/user/user.module
@@ -735,112 +735,135 @@ function user_login_block() {
}
/**
- * Implementation of hook_block().
+ * Implementation of hook_block_list().
*/
-function user_block($op = 'list', $delta = '', $edit = array()) {
+function user_block_list() {
global $user;
- if ($op == 'list') {
- $blocks['login']['info'] = t('User login');
- // Not worth caching.
- $blocks['login']['cache'] = BLOCK_NO_CACHE;
-
- $blocks['navigation']['info'] = t('Navigation');
- // Menu blocks can't be cached because each menu item can have
- // a custom access callback. menu.inc manages its own caching.
- $blocks['navigation']['cache'] = BLOCK_NO_CACHE;
-
- $blocks['new']['info'] = t('Who\'s new');
-
- // Too dynamic to cache.
- $blocks['online']['info'] = t('Who\'s online');
- $blocks['online']['cache'] = BLOCK_NO_CACHE;
- return $blocks;
- }
- elseif ($op == 'configure' && $delta == 'new') {
- $form['user_block_whois_new_count'] = array(
- '#type' => 'select',
- '#title' => t('Number of users to display'),
- '#default_value' => variable_get('user_block_whois_new_count', 5),
- '#options' => drupal_map_assoc(array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)),
- );
- return $form;
- }
- elseif ($op == 'configure' && $delta == 'online') {
- $period = drupal_map_assoc(array(30, 60, 120, 180, 300, 600, 900, 1800, 2700, 3600, 5400, 7200, 10800, 21600, 43200, 86400), 'format_interval');
- $form['user_block_seconds_online'] = array('#type' => 'select', '#title' => t('User activity'), '#default_value' => variable_get('user_block_seconds_online', 900), '#options' => $period, '#description' => t('A user is considered online for this long after they have last viewed a page.'));
- $form['user_block_max_list_count'] = array('#type' => 'select', '#title' => t('User list length'), '#default_value' => variable_get('user_block_max_list_count', 10), '#options' => drupal_map_assoc(array(0, 5, 10, 15, 20, 25, 30, 40, 50, 75, 100)), '#description' => t('Maximum number of currently online users to display.'));
+ $blocks['login']['info'] = t('User login');
+ // Not worth caching.
+ $blocks['login']['cache'] = BLOCK_NO_CACHE;
- return $form;
- }
- elseif ($op == 'save' && $delta == 'new') {
- variable_set('user_block_whois_new_count', $edit['user_block_whois_new_count']);
+ $blocks['navigation']['info'] = t('Navigation');
+ // Menu blocks can't be cached because each menu item can have
+ // a custom access callback. menu.inc manages its own caching.
+ $blocks['navigation']['cache'] = BLOCK_NO_CACHE;
+
+ $blocks['new']['info'] = t('Who\'s new');
+
+ // Too dynamic to cache.
+ $blocks['online']['info'] = t('Who\'s online');
+ $blocks['online']['cache'] = BLOCK_NO_CACHE;
+ return $blocks;
+}
+
+/**
+ * Implementation of hook_block_configure().
+ */
+function user_block_configure($delta = '') {
+ global $user;
+
+ switch($delta) {
+ case 'new':
+ $form['user_block_whois_new_count'] = array(
+ '#type' => 'select',
+ '#title' => t('Number of users to display'),
+ '#default_value' => variable_get('user_block_whois_new_count', 5),
+ '#options' => drupal_map_assoc(array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)),
+ );
+ return $form;
+
+ case 'online':
+ $period = drupal_map_assoc(array(30, 60, 120, 180, 300, 600, 900, 1800, 2700, 3600, 5400, 7200, 10800, 21600, 43200, 86400), 'format_interval');
+ $form['user_block_seconds_online'] = array('#type' => 'select', '#title' => t('User activity'), '#default_value' => variable_get('user_block_seconds_online', 900), '#options' => $period, '#description' => t('A user is considered online for this long after they have last viewed a page.'));
+ $form['user_block_max_list_count'] = array('#type' => 'select', '#title' => t('User list length'), '#default_value' => variable_get('user_block_max_list_count', 10), '#options' => drupal_map_assoc(array(0, 5, 10, 15, 20, 25, 30, 40, 50, 75, 100)), '#description' => t('Maximum number of currently online users to display.'));
+ return $form;
}
- elseif ($op == 'save' && $delta == 'online') {
- variable_set('user_block_seconds_online', $edit['user_block_seconds_online']);
- variable_set('user_block_max_list_count', $edit['user_block_max_list_count']);
+}
+
+/**
+ * Implementation of hook_block_save().
+ */
+function user_block_save($delta = '', $edit = array()) {
+ global $user;
+
+ switch ($delta) {
+ case 'new':
+ variable_set('user_block_whois_new_count', $edit['user_block_whois_new_count']);
+ break;
+
+ case 'online':
+ variable_set('user_block_seconds_online', $edit['user_block_seconds_online']);
+ variable_set('user_block_max_list_count', $edit['user_block_max_list_count']);
+ break;
}
- elseif ($op == 'view') {
- $block = array();
+}
- switch ($delta) {
- case 'login':
- // For usability's sake, avoid showing two login forms on one page.
- if (!$user->uid && !(arg(0) == 'user' && !is_numeric(arg(1)))) {
+/**
+ * Implementation of hook_block_view().
+ */
+function user_block_view($delta = '') {
+ global $user;
- $block['subject'] = t('User login');
- $block['content'] = drupal_get_form('user_login_block');
- }
- return $block;
+ $block = array();
- case 'navigation':
- if ($menu = menu_tree()) {
- $block['subject'] = $user->uid ? check_plain($user->name) : t('Navigation');
- $block['content'] = $menu;
- }
- return $block;
+ switch ($delta) {
+ case 'login':
+ // For usability's sake, avoid showing two login forms on one page.
+ if (!$user->uid && !(arg(0) == 'user' && !is_numeric(arg(1)))) {
- case 'new':
- if (user_access('access content')) {
- // Retrieve a list of new users who have subsequently accessed the site successfully.
- $items = db_query_range('SELECT uid, name FROM {users} WHERE status != 0 AND access != 0 ORDER BY created DESC', array(), 0, variable_get('user_block_whois_new_count', 5))->fetchAll();
- $output = theme('user_list', $items);
+ $block['subject'] = t('User login');
+ $block['content'] = drupal_get_form('user_login_block');
+ }
+ return $block;
- $block['subject'] = t('Who\'s new');
- $block['content'] = $output;
- }
- return $block;
+ case 'navigation':
+ if ($menu = menu_tree()) {
+ $block['subject'] = $user->uid ? check_plain($user->name) : t('Navigation');
+ $block['content'] = $menu;
+ }
+ return $block;
- case 'online':
- if (user_access('access content')) {
- // Count users active within the defined period.
- $interval = REQUEST_TIME - variable_get('user_block_seconds_online', 900);
+ case 'new':
+ if (user_access('access content')) {
+ // Retrieve a list of new users who have subsequently accessed the site successfully.
+ $items = db_query_range('SELECT uid, name FROM {users} WHERE status != 0 AND access != 0 ORDER BY created DESC', array(), 0, variable_get('user_block_whois_new_count', 5))->fetchAll();
+ $output = theme('user_list', $items);
- // Perform database queries to gather online user lists. We use s.timestamp
- // rather than u.access because it is much faster.
- $anonymous_count = drupal_session_count($interval);
- $authenticated_count = db_query("SELECT COUNT(DISTINCT s.uid) FROM {sessions} s WHERE s.timestamp >= :timestamp AND s.uid > 0", array(':timestamp' => $interval))->fetchField();
+ $block['subject'] = t('Who\'s new');
+ $block['content'] = $output;
+ }
+ return $block;
- // Format the output with proper grammar.
- if ($anonymous_count == 1 && $authenticated_count == 1) {
- $output = t('There is currently %members and %visitors online.', array('%members' => format_plural($authenticated_count, '1 user', '@count users'), '%visitors' => format_plural($anonymous_count, '1 guest', '@count guests')));
- }
- else {
- $output = t('There are currently %members and %visitors online.', array('%members' => format_plural($authenticated_count, '1 user', '@count users'), '%visitors' => format_plural($anonymous_count, '1 guest', '@count guests')));
- }
+ case 'online':
+ if (user_access('access content')) {
+ // Count users active within the defined period.
+ $interval = REQUEST_TIME - variable_get('user_block_seconds_online', 900);
- // Display a list of currently online users.
- $max_users = variable_get('user_block_max_list_count', 10);
- if ($authenticated_count && $max_users) {
- $items = db_query_range('SELECT u.uid, u.name, MAX(s.timestamp) AS max_timestamp FROM {users} u INNER JOIN {sessions} s ON u.uid = s.uid WHERE s.timestamp >= :interval AND s.uid > 0 GROUP BY u.uid, u.name ORDER BY max_timestamp DESC', array(':interval' => $interval), 0, $max_users)->fetchAll();
- $output .= theme('user_list', $items, t('Online users'));
- }
+ // Perform database queries to gather online user lists. We use s.timestamp
+ // rather than u.access because it is much faster.
+ $anonymous_count = drupal_session_count($interval);
+ $authenticated_count = db_query("SELECT COUNT(DISTINCT s.uid) FROM {sessions} s WHERE s.timestamp >= :timestamp AND s.uid > 0", array(':timestamp' => $interval))->fetchField();
- $block['subject'] = t('Who\'s online');
- $block['content'] = $output;
+ // Format the output with proper grammar.
+ if ($anonymous_count == 1 && $authenticated_count == 1) {
+ $output = t('There is currently %members and %visitors online.', array('%members' => format_plural($authenticated_count, '1 user', '@count users'), '%visitors' => format_plural($anonymous_count, '1 guest', '@count guests')));
}
- return $block;
- }
+ else {
+ $output = t('There are currently %members and %visitors online.', array('%members' => format_plural($authenticated_count, '1 user', '@count users'), '%visitors' => format_plural($anonymous_count, '1 guest', '@count guests')));
+ }
+
+ // Display a list of currently online users.
+ $max_users = variable_get('user_block_max_list_count', 10);
+ if ($authenticated_count && $max_users) {
+ $items = db_query_range('SELECT u.uid, u.name, MAX(s.timestamp) AS max_timestamp FROM {users} u INNER JOIN {sessions} s ON u.uid = s.uid WHERE s.timestamp >= :interval AND s.uid > 0 GROUP BY u.uid, u.name ORDER BY max_timestamp DESC', array(':interval' => $interval), 0, $max_users)->fetchAll();
+ $output .= theme('user_list', $items, t('Online users'));
+ }
+
+ $block['subject'] = t('Who\'s online');
+ $block['content'] = $output;
+ }
+ return $block;
}
}
diff --git a/modules/user/user.test b/modules/user/user.test
index 981539b8787a45b4ce6640cc3a878277af8d9452..01b5b50f78151e7c0280f3f4688a02c2f2a92491 100644
--- a/modules/user/user.test
+++ b/modules/user/user.test
@@ -647,7 +647,7 @@ class UserBlocksUnitTests extends DrupalWebTestCase {
$this->insertSession();
// Test block output.
- $block = user_block('view', 'online');
+ $block = user_block_view('online');
$this->drupalSetContent($block['content']);
$this->assertRaw(t('%members and %visitors', array('%members' => '2 users', '%visitors' => '2 guests')), t('Correct number of online users (2 users and 2 guests).'));
$this->assertText($user1->name, t('Active user 1 found in online list.'));