#561970 by Davy Van Den Bremt: Rename 'box' to 'custom block'. Here's to core's database schema making sense.

merge-requests/26/head
Angie Byron 2009-08-28 19:44:05 +00:00
parent 3dea934d2b
commit f4c6b2ba5e
7 changed files with 91 additions and 82 deletions

View File

@ -357,11 +357,11 @@ function block_admin_configure(&$form_state, $module = NULL, $delta = 0) {
function block_admin_configure_validate($form, &$form_state) {
if ($form_state['values']['module'] == 'block') {
$box_exists = (bool) db_query_range('SELECT 1 FROM {box} WHERE bid <> :bid AND info = :info', array(
$custom_block_exists = (bool) db_query_range('SELECT 1 FROM {block_custom} WHERE bid <> :bid AND info = :info', array(
':bid' => $form_state['values']['delta'],
':info' => $form_state['values']['info'],
), 0, 1)->fetchField();
if (empty($form_state['values']['info']) || $box_exists) {
if (empty($form_state['values']['info']) || $custom_block_exists) {
form_set_error('info', t('Please ensure that each block description is unique.'));
}
}
@ -435,9 +435,9 @@ function block_add_block_form(&$form_state) {
}
function block_add_block_form_validate($form, &$form_state) {
$box_exists = (bool) db_query_range('SELECT 1 FROM {box} WHERE info = :info', array(':info' => $form_state['values']['info']), 0, 1)->fetchField();
$custom_block_exists = (bool) db_query_range('SELECT 1 FROM {block_custom} WHERE info = :info', array(':info' => $form_state['values']['info']), 0, 1)->fetchField();
if (empty($form_state['values']['info']) || $box_exists) {
if (empty($form_state['values']['info']) || $custom_block_exists) {
form_set_error('info', t('Please ensure that each block description is unique.'));
}
}
@ -446,7 +446,7 @@ function block_add_block_form_validate($form, &$form_state) {
* Save the new custom block.
*/
function block_add_block_form_submit($form, &$form_state) {
$delta = db_insert('box')
$delta = db_insert('block_custom')
->fields(array(
'body' => $form_state['values']['body'],
'info' => $form_state['values']['info'],
@ -513,19 +513,19 @@ function block_add_block_form_submit($form, &$form_state) {
/**
* Menu callback; confirm deletion of custom blocks.
*/
function block_box_delete(&$form_state, $bid = 0) {
$box = block_box_get($bid);
$form['info'] = array('#type' => 'hidden', '#value' => $box['info'] ? $box['info'] : $box['title']);
function block_custom_block_delete(&$form_state, $bid = 0) {
$custom_block = block_custom_block_get($bid);
$form['info'] = array('#type' => 'hidden', '#value' => $custom_block['info'] ? $custom_block['info'] : $custom_block['title']);
$form['bid'] = array('#type' => 'hidden', '#value' => $bid);
return confirm_form($form, t('Are you sure you want to delete the block %name?', array('%name' => $box['info'])), 'admin/structure/block', '', t('Delete'), t('Cancel'));
return confirm_form($form, t('Are you sure you want to delete the block %name?', array('%name' => $custom_block['info'])), 'admin/structure/block', '', t('Delete'), t('Cancel'));
}
/**
* Deletion of custom blocks.
*/
function block_box_delete_submit($form, &$form_state) {
db_delete('box')
function block_custom_block_delete_submit($form, &$form_state) {
db_delete('block_custom')
->condition('bid', $form_state['values']['bid'])
->execute();
db_delete('block')

View File

@ -1,7 +1,7 @@
; $Id$
name = Block
description = Controls the boxes that are displayed around the main content.
description = Controls the visual building blocks a page is constructed with. Blocks are boxes of content rendered into an area, or region, of a web page.
package = Core
version = VERSION
core = 7.x

View File

@ -159,7 +159,7 @@ function block_schema() {
),
);
$schema['box'] = array(
$schema['block_custom'] = array(
'description' => 'Stores contents of custom-made blocks.',
'fields' => array(
'bid' => array(

View File

@ -3,7 +3,7 @@
/**
* @file
* Controls the boxes that are displayed around the main content.
* Controls the visual building blocks a page is constructed with.
*/
/**
@ -150,7 +150,7 @@ function block_menu() {
$items['admin/structure/block/delete'] = array(
'title' => 'Delete block',
'page callback' => 'drupal_get_form',
'page arguments' => array('block_box_delete'),
'page arguments' => array('block_custom_block_delete'),
'access arguments' => array('administer blocks'),
'type' => MENU_CALLBACK,
'file' => 'block.admin.inc',
@ -192,7 +192,7 @@ function _block_themes_access($theme) {
function block_block_list() {
$blocks = array();
$result = db_query('SELECT bid, info FROM {box} ORDER BY info');
$result = db_query('SELECT bid, info FROM {block_custom} ORDER BY info');
foreach ($result as $block) {
$blocks[$block->bid]['info'] = $block->info;
// Not worth caching.
@ -205,18 +205,18 @@ function block_block_list() {
* Implement hook_block_configure().
*/
function block_block_configure($delta = 0) {
$box = array('format' => FILTER_FORMAT_DEFAULT);
$custom_block = array('format' => FILTER_FORMAT_DEFAULT);
if ($delta) {
$box = block_box_get($delta);
$custom_block = block_custom_block_get($delta);
}
return block_box_form($box);
return block_custom_block_form($custom_block);
}
/**
* Implement hook_block_save().
*/
function block_block_save($delta = 0, $edit = array()) {
block_box_save($edit, $delta);
block_custom_block_save($edit, $delta);
}
/**
@ -225,7 +225,7 @@ function block_block_save($delta = 0, $edit = array()) {
* Generates the administrator-defined blocks for display.
*/
function block_block_view($delta = 0, $edit = array()) {
$block = db_query('SELECT body, format FROM {box} WHERE bid = :bid', array(':bid' => $delta))->fetchObject();
$block = db_query('SELECT body, format FROM {block_custom} WHERE bid = :bid', array(':bid' => $delta))->fetchObject();
$data['content'] = check_markup($block->body, $block->format);
return $data;
}
@ -372,14 +372,14 @@ function _block_rehash() {
return $blocks;
}
function block_box_get($bid) {
return db_query("SELECT * FROM {box} WHERE bid = :bid", array(':bid' => $bid))->fetchAssoc();
function block_custom_block_get($bid) {
return db_query("SELECT * FROM {block_custom} WHERE bid = :bid", array(':bid' => $bid))->fetchAssoc();
}
/**
* Define the custom block form.
*/
function block_box_form($edit = array()) {
function block_custom_block_form($edit = array()) {
$edit += array(
'info' => '',
'body' => '',
@ -409,8 +409,8 @@ function block_box_form($edit = array()) {
return $form;
}
function block_box_save($edit, $delta) {
db_update('box')
function block_custom_block_save($edit, $delta) {
db_update('block_custom')
->fields(array(
'body' => $edit['body'],
'info' => $edit['info'],
@ -868,7 +868,7 @@ function block_user_role_delete($role) {
* Implement hook_filter_format_delete().
*/
function block_filter_format_delete($format, $default) {
db_update('box')
db_update('block_custom')
->fields(array('format' => $default->format))
->condition('format', $format->format)
->execute();

View File

@ -34,57 +34,57 @@ class BlockTestCase extends DrupalWebTestCase {
}
/**
* Test creating custom block (i.e. box), moving it to a specific region and then deleting it.
* Test creating custom block, moving it to a specific region and then deleting it.
*/
function testBox() {
// Add a new box by filling out the input form on the admin/structure/block/add page.
$box = array();
$box['info'] = $this->randomName(8);
$box['title'] = $this->randomName(8);
$box['body'] = $this->randomName(32);
$this->drupalPost('admin/structure/block/add', $box, t('Save block'));
function testCustomBlock() {
// Add a new custom block by filling out the input form on the admin/structure/block/add page.
$custom_block = array();
$custom_block['info'] = $this->randomName(8);
$custom_block['title'] = $this->randomName(8);
$custom_block['body'] = $this->randomName(32);
$this->drupalPost('admin/structure/block/add', $custom_block, t('Save block'));
// Confirm that the box has been created, and then query the created bid.
$this->assertText(t('The block has been created.'), t('Box successfully created.'));
$bid = db_query("SELECT bid FROM {box} WHERE info = :info", array(':info' => $box['info']))->fetchField();
// Confirm that the custom block has been created, and then query the created bid.
$this->assertText(t('The block has been created.'), t('Custom block successfully created.'));
$bid = db_query("SELECT bid FROM {block_custom} WHERE info = :info", array(':info' => $custom_block['info']))->fetchField();
// Check to see if the box was created by checking that it's in the database..
$this->assertNotNull($bid, t('Box found in database'));
// Check to see if the custom block was created by checking that it's in the database..
$this->assertNotNull($bid, t('Custom block found in database'));
// Check if the block can be moved to all availble regions.
$box['module'] = 'block';
$box['delta'] = $bid;
$custom_block['module'] = 'block';
$custom_block['delta'] = $bid;
foreach ($this->regions as $region) {
$this->moveBlockToRegion($box, $region);
$this->moveBlockToRegion($custom_block, $region);
}
// Delete the created box & verify that it's been deleted and no longer appearing on the page.
// Delete the created custom block & verify that it's been deleted and no longer appearing on the page.
$this->clickLink(t('delete'));
$this->drupalPost('admin/structure/block/delete/' . $bid, array(), t('Delete'));
$this->assertRaw(t('The block %title has been removed.', array('%title' => $box['info'])), t('Box successfully deleted.'));
$this->assertNoText(t($box['title']), t('Box no longer appears on page.'));
$this->assertRaw(t('The block %title has been removed.', array('%title' => $custom_block['info'])), t('Custom block successfully deleted.'));
$this->assertNoText(t($custom_block['title']), t('Custom block no longer appears on page.'));
}
/**
* Test creating custom block (i.e. box) using Full HTML.
* Test creating custom block using Full HTML.
*/
function testBoxFormat() {
// Add a new box by filling out the input form on the admin/structure/block/add page.
$box = array();
$box['info'] = $this->randomName(8);
$box['title'] = $this->randomName(8);
$box['body'] = '<h1>Full HTML</h1>';
$box['body_format'] = 2;
$this->drupalPost('admin/structure/block/add', $box, t('Save block'));
function testCustomBlockFormat() {
// Add a new custom block by filling out the input form on the admin/structure/block/add page.
$custom_block = array();
$custom_block['info'] = $this->randomName(8);
$custom_block['title'] = $this->randomName(8);
$custom_block['body'] = '<h1>Full HTML</h1>';
$custom_block['body_format'] = 2;
$this->drupalPost('admin/structure/block/add', $custom_block, t('Save block'));
// Set the created box to a specific region.
$bid = db_query("SELECT bid FROM {box} WHERE info = :info", array(':info' => $box['info']))->fetchField();
// Set the created custom block to a specific region.
$bid = db_query("SELECT bid FROM {block_custom} WHERE info = :info", array(':info' => $custom_block['info']))->fetchField();
$edit = array();
$edit['block_' . $bid . '[region]'] = $this->regions[1]['name'];
$this->drupalPost('admin/structure/block', $edit, t('Save blocks'));
// Confirm that the box is being displayed using configured text format.
$this->assertRaw('<h1>Full HTML</h1>', t('Box successfully being displayed using Full HTML.'));
// Confirm that the custom block is being displayed using configured text format.
$this->assertRaw('<h1>Full HTML</h1>', t('Custom block successfully being displayed using Full HTML.'));
// Confirm that a user without access to Full HTML can not see the body field,
// but can still submit the form without errors.
@ -95,8 +95,8 @@ class BlockTestCase extends DrupalWebTestCase {
$this->drupalPost('admin/structure/block/configure/block/' . $bid, array(), t('Save block'));
$this->assertNoText(t('Please ensure that each block description is unique.'));
// Confirm that the box is still being displayed using configured text format.
$this->assertRaw('<h1>Full HTML</h1>', t('Box successfully being displayed using Full HTML.'));
// Confirm that the custom block is still being displayed using configured text format.
$this->assertRaw('<h1>Full HTML</h1>', t('Custom block successfully being displayed using Full HTML.'));
}
/**
@ -109,13 +109,13 @@ class BlockTestCase extends DrupalWebTestCase {
$title = $this->randomName(8);
// Create the custom block
$box = array();
$box['info'] = $this->randomName(8);
$box['title'] = $title;
$box['body'] = $this->randomName(32);
$this->drupalPost('admin/structure/block/add', $box, t('Save block'));
$custom_block = array();
$custom_block['info'] = $this->randomName(8);
$custom_block['title'] = $title;
$custom_block['body'] = $this->randomName(32);
$this->drupalPost('admin/structure/block/add', $custom_block, t('Save block'));
$bid = db_query("SELECT bid FROM {box} WHERE info = :info", array(':info' => $box['info']))->fetchField();
$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;
@ -179,7 +179,7 @@ class BlockTestCase extends DrupalWebTestCase {
// Confirm that the regions xpath is not availble
$xpath = '//div[@id="block-block-' . $bid . '"]/*';
$this->assertNoFieldByXPath($xpath, FALSE, t('Box found in no regions.'));
$this->assertNoFieldByXPath($xpath, FALSE, t('Custom block found in no regions.'));
// For convenience of developers, put the navigation block back.
$edit = array();
@ -208,9 +208,9 @@ class BlockTestCase extends DrupalWebTestCase {
// Confirm that the block is being displayed.
$this->assertText(t($block['title']), t('Block successfully being displayed on the page.'));
// Confirm that the box was found at the proper region.
// Confirm that the custom block was found at the proper region.
$xpath = '//div[@id="' . $region['id'] . '"]//div[@id="block-' . $block['module'] . '-' . $block['delta'] . '"]/*';
$this->assertFieldByXPath($xpath, FALSE, t('Box found in %region_name region.', array('%region_name' => $region['name'])));
$this->assertFieldByXPath($xpath, FALSE, t('Custom block found in %region_name region.', array('%region_name' => $region['name'])));
}
}

View File

@ -787,17 +787,17 @@ class FilterHooksTestCase extends DrupalWebTestCase {
$this->assertText('hook_filter_format_update invoked.', t('hook_filter_format_update() was invoked.'));
// Add a new custom block.
$box = array();
$box['info'] = $this->randomName(8);
$box['title'] = $this->randomName(8);
$box['body'] = $this->randomName(32);
$custom_block = array();
$custom_block['info'] = $this->randomName(8);
$custom_block['title'] = $this->randomName(8);
$custom_block['body'] = $this->randomName(32);
// Use the format created.
$box['body_format'] = $format;
$this->drupalPost('admin/structure/block/add', $box, t('Save block'));
$custom_block['body_format'] = $format;
$this->drupalPost('admin/structure/block/add', $custom_block, t('Save block'));
$this->assertText(t('The block has been created.'), t('New block successfully created.'));
// Verify the new block is in the database.
$bid = db_query("SELECT bid FROM {box} WHERE info = :info", array(':info' => $box['info']))->fetchField();
$bid = db_query("SELECT bid FROM {block_custom} WHERE info = :info", array(':info' => $custom_block['info']))->fetchField();
$this->assertNotNull($bid, t('New block found in database'));
// Delete the text format.
@ -806,7 +806,7 @@ class FilterHooksTestCase extends DrupalWebTestCase {
$this->assertText('hook_filter_format_delete invoked.', t('hook_filter_format_delete() was invoked.'));
// Verify that the deleted format was replaced with the default format.
$current_format = db_select('box', 'b')
$current_format = db_select('block_custom', 'b')
->fields('b', array('format'))
->condition('bid', $bid)
->execute()

View File

@ -2040,7 +2040,7 @@ function system_update_7021() {
// Migrate contact form information.
if ($contact_help = variable_get('contact_form_information', '')) {
$bid = db_insert('box')->fields(array('body' => $contact_help, 'info' => 'Contact page help', 'format' => FILTER_FORMAT_DEFAULT))->execute();
$bid = db_insert('block_custom')->fields(array('body' => $contact_help, 'info' => 'Contact page help', 'format' => FILTER_FORMAT_DEFAULT))->execute();
foreach ($themes_with_blocks as $theme) {
// Add contact help block for themes, which had blocks.
$ret[] = update_sql("INSERT INTO {block} (module, delta, theme, status, weight, region, visibility, pages, cache) VALUES ('block', '" . $bid . "', '" . $theme . "', 1, 5, 'help', 1, 'contact', -1)");
@ -2050,7 +2050,7 @@ function system_update_7021() {
// Migrate user help setting.
if ($user_help = variable_get('user_registration_help', '')) {
$bid = db_insert('box')->fields(array('body' => $user_help, 'info' => 'User registration guidelines', 'format' => FILTER_FORMAT_DEFAULT))->execute();
$bid = db_insert('block_custom')->fields(array('body' => $user_help, 'info' => 'User registration guidelines', 'format' => FILTER_FORMAT_DEFAULT))->execute();
foreach ($themes_with_blocks as $theme) {
// Add user registration help block for themes, which had blocks.
$ret[] = update_sql("INSERT INTO {block} (module, delta, theme, status, weight, region, visibility, pages, cache) VALUES ('block', '" . $bid . "', '" . $theme . "', 1, 5, 'help', 1, 'user/register', -1)");
@ -2060,7 +2060,7 @@ function system_update_7021() {
// Migrate site mission setting.
if ($mission = variable_get('site_mission')) {
$bid = db_insert('box')->fields(array('body' => $mission, 'info' => 'Site mission', 'format' => FILTER_FORMAT_DEFAULT))->execute();
$bid = db_insert('block_custom')->fields(array('body' => $mission, 'info' => 'Site mission', 'format' => FILTER_FORMAT_DEFAULT))->execute();
foreach ($themes_with_blocks as $theme) {
// Add mission block for themes, which had blocks.
$ret[] = update_sql("INSERT INTO {block} (module, delta, theme, status, weight, region, visibility, pages, cache) VALUES ('block', '" . $bid . "', '" . $theme . "', 1, 0, 'highlight', 1, '<front>', -1)");
@ -2072,7 +2072,7 @@ function system_update_7021() {
// Migrate site footer message to a custom block.
if ($footer_message = variable_get('site_footer', '')) {
$bid = db_insert('box')->fields(array('body' => $footer_message, 'info' => 'Footer message', 'format' => FILTER_FORMAT_DEFAULT))->execute();
$bid = db_insert('block_custom')->fields(array('body' => $footer_message, 'info' => 'Footer message', 'format' => FILTER_FORMAT_DEFAULT))->execute();
foreach ($themes_with_blocks as $theme) {
// Add site footer block for themes, which had blocks.
// Set low weight, so the block comes early (it used to be
@ -2449,6 +2449,15 @@ function system_update_7036() {
return $ret;
}
/**
* Rename {box} table to {block_custom}.
*/
function system_update_7037() {
$ret = array();
db_rename_table($ret, 'box', 'block_custom');
return $ret;
}
/**
* @} End of "defgroup updates-6.x-to-7.x"
* The next series of updates should start at 8000.