diff --git modules/block/block.admin.inc modules/block/block.admin.inc
index 27f9669..d90c689 100644
--- modules/block/block.admin.inc
+++ modules/block/block.admin.inc
@@ -100,7 +100,7 @@ function block_admin_display_form(&$form_state, $blocks, $theme = NULL) {
);
$form[$key]['configure'] = array(
'#markup' => l(t('configure'),
- 'admin/structure/block/configure/' . $block['module'] . '/' . $block['delta']),
+ 'admin/structure/block/configure/' . $block['module'] . '_' . $block['delta']),
);
if ($block['module'] == 'block') {
$form[$key]['delete'] = array(
@@ -179,7 +179,13 @@ function _block_compare($a, $b) {
/**
* Menu callback; displays the block configuration form.
*/
-function block_admin_configure(&$form_state, $module = NULL, $delta = 0) {
+function block_admin_configure(&$form_state, $args = NULL) {
+ $module = NULL;
+ $delta = 0;
+ if ($args) {
+ list($module, $delta) = explode('_', $args);
+ }
+
$form['module'] = array(
'#type' => 'value',
'#value' => $module,
@@ -189,22 +195,28 @@ function block_admin_configure(&$form_state, $module = NULL, $delta = 0) {
'#value' => $delta,
);
- $edit = db_query("SELECT pages, visibility, custom, title FROM {block} WHERE module = :module AND delta = :delta", array(
+ $block = db_query("SELECT block_id, pages, visibility, custom, title FROM {block} WHERE module = :module AND delta = :delta", array(
':module' => $module,
':delta' => $delta,
- ))->fetchAssoc();
+ ))->fetchObject();
+
+ $form['block_id'] = array(
+ '#type' => 'value',
+ '#value' => $block->block_id,
+ );
$form['block_settings'] = array(
'#type' => 'fieldset',
'#title' => t('Block specific settings'),
'#collapsible' => TRUE,
+ '#weight' => -10,
);
$form['block_settings']['title'] = array(
'#type' => 'textfield',
'#title' => t('Block title'),
'#maxlength' => 64,
'#description' => $module == 'block' ? t('The title of the block as shown to the user.') : t('Override the default title for the block. Use <none> to display no title, or leave blank to use the default block title.'),
- '#default_value' => $edit['title'],
+ '#default_value' => $block->title,
'#weight' => -18,
);
@@ -216,6 +228,7 @@ function block_admin_configure(&$form_state, $module = NULL, $delta = 0) {
'#collapsed' => TRUE,
'#description' => t('Specify in which region this block is displayed.'),
'#tree' => TRUE,
+ '#weight' => 30,
);
$theme_default = variable_get('theme_default', 'garland');
@@ -254,18 +267,26 @@ function block_admin_configure(&$form_state, $module = NULL, $delta = 0) {
drupal_set_title(t("'%name' block", array('%name' => $info[$delta]['info'])), PASS_THROUGH);
}
+ // Attach fields.
+ if ($block->block_id) {
+ $block->block_machine_name = $module . '_' . $delta;
+ field_attach_load('block', array($block->block_id => $block));
+ field_attach_form('block', $block, $form, $form_state);
+ }
+
$form['page_vis_settings'] = array(
'#type' => 'fieldset',
'#title' => t('Page specific visibility settings'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
+ '#weight' => 31,
);
$access = user_access('use PHP for settings');
- if ($edit['visibility'] == 2 && !$access) {
+ if ($block->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']);
+ $form['page_vis_settings']['pages'] = array('#type' => 'value', '#value' => $block->pages);
}
else {
$options = array(t('Every page except those specified below.'), t('Only the pages specified below.'));
@@ -279,12 +300,12 @@ function block_admin_configure(&$form_state, $module = NULL, $delta = 0) {
'#type' => 'radios',
'#title' => t('Show block on specific pages'),
'#options' => $options,
- '#default_value' => $edit['visibility'],
+ '#default_value' => $block->visibility,
);
$form['page_vis_settings']['pages'] = array(
'#type' => 'textarea',
'#title' => t('Pages'),
- '#default_value' => $edit['pages'],
+ '#default_value' => $block->pages,
'#description' => $description,
);
}
@@ -300,6 +321,7 @@ function block_admin_configure(&$form_state, $module = NULL, $delta = 0) {
'#title' => t('Role specific visibility settings'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
+ '#weight' => 32,
);
$form['role_vis_settings']['roles'] = array(
'#type' => 'checkboxes',
@@ -319,6 +341,7 @@ function block_admin_configure(&$form_state, $module = NULL, $delta = 0) {
'#title' => t('Content type specific visibility settings'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
+ '#weight' => 33,
);
$form['content_type_vis_settings']['types'] = array(
'#type' => 'checkboxes',
@@ -334,6 +357,7 @@ function block_admin_configure(&$form_state, $module = NULL, $delta = 0) {
'#title' => t('User specific visibility settings'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
+ '#weight' => 34,
);
$form['user_vis_settings']['custom'] = array(
'#type' => 'radios',
@@ -344,12 +368,13 @@ function block_admin_configure(&$form_state, $module = NULL, $delta = 0) {
t('Hide this block by default but let individual users show it.')
),
'#description' => t('Allow individual users to customize the visibility of this block in their account settings.'),
- '#default_value' => $edit['custom'],
+ '#default_value' => $block->custom,
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save block'),
+ '#weight' => 40,
);
return $form;
@@ -365,10 +390,18 @@ function block_admin_configure_validate($form, &$form_state) {
form_set_error('info', t('Please ensure that each block description is unique.'));
}
}
+ $block = (object) $form_state['values'];
+ $block->block_machine_name = $block->module . '_' . $block->delta;
+ field_attach_form_validate('block', $block, $form, $form_state);
}
function block_admin_configure_submit($form, &$form_state) {
if (!form_get_errors()) {
+ $block = (object) $form_state['values'];
+ $block->block_machine_name = $block->module . '_' . $block->delta;
+ field_attach_submit('block', $block, $form, $form_state);
+ field_attach_presave('block', $block);
+
db_update('block')
->fields(array(
'visibility' => (int) $form_state['values']['visibility'],
@@ -420,6 +453,8 @@ function block_admin_configure_submit($form, &$form_state) {
->execute();
}
+ field_attach_update('block', $block);
+
module_invoke($form_state['values']['module'], 'block_save', $form_state['values']['delta'], $form_state['values']);
drupal_set_message(t('The block configuration has been saved.'));
cache_clear_all();
@@ -431,7 +466,10 @@ function block_admin_configure_submit($form, &$form_state) {
* Menu callback: display the custom block addition form.
*/
function block_add_block_form(&$form_state) {
- return block_admin_configure($form_state, 'block', NULL);
+ // Use argument 'block_' so that block_admin_configure() assigns the $module
+ // varialble but not the $delta variable. Needed when creating a new block
+ // since we do not know what the $delta is yet.
+ return block_admin_configure($form_state, 'block_');
}
function block_add_block_form_validate($form, &$form_state) {
@@ -448,30 +486,30 @@ function block_add_block_form_validate($form, &$form_state) {
function block_add_block_form_submit($form, &$form_state) {
$delta = db_insert('box')
->fields(array(
- 'body' => $form_state['values']['body'],
'info' => $form_state['values']['info'],
- 'format' => $form_state['values']['body_format'],
))
->execute();
- $query = db_insert('block')->fields(array('visibility', 'pages', 'custom', 'title', 'module', 'theme', 'status', 'weight', 'delta', 'cache'));
+ $block = array(
+ 'visibility' => (int) $form_state['values']['visibility'],
+ 'pages' => trim($form_state['values']['pages']),
+ 'custom' => (int) $form_state['values']['custom'],
+ 'title' => $form_state['values']['title'],
+ 'module' => $form_state['values']['module'],
+ 'status' => 0,
+ 'weight' => 0,
+ 'delta' => $delta,
+ 'cache' => BLOCK_NO_CACHE,
+ );
+
foreach (list_themes() as $key => $theme) {
if ($theme->status) {
- $query->values(array(
- 'visibility' => (int) $form_state['values']['visibility'],
- 'pages' => trim($form_state['values']['pages']),
- 'custom' => (int) $form_state['values']['custom'],
- 'title' => $form_state['values']['title'],
- 'module' => $form_state['values']['module'],
- 'theme' => $theme->name,
- 'status' => 0,
- 'weight' => 0,
- 'delta' => $delta,
- 'cache' => BLOCK_NO_CACHE,
- ));
+ // Make sure we are creating a new instance of the block for each theme.
+ unset($block['bid']);
+ $block['theme'] = $theme->name;
+ $block = block_save($block);
}
}
- $query->execute();
$query = db_insert('block_role')->fields(array('rid', 'module', 'delta'));
foreach (array_filter($form_state['values']['roles']) as $rid) {
@@ -493,6 +531,34 @@ function block_add_block_form_submit($form, &$form_state) {
}
$query->execute();
+ // Create the 'block_body' field if it doesn't already exist.
+ $field = field_info_field('block_body');
+ if (empty($field)) {
+ $field = array(
+ 'field_name' => 'block_body',
+ 'type' => 'text_long',
+ );
+ field_create_field($field);
+ }
+
+ // Attach an instance of the 'block_body' field to the new block bundle.
+ $instance = array(
+ 'field_name' => 'block_body',
+ 'bundle' => 'block_' . $delta,
+ 'label' => t('Block body'),
+ 'description' => t('The content of the block as shown to the user.'),
+ 'required' => TRUE,
+ 'settings' => array('text_processing' => 1),
+ 'widget' => array(
+ 'type' => 'text_textarea',
+ 'label' => t('Block body'),
+ ),
+ 'display' => array(
+ 'full' => array('label' => 'hidden'),
+ ),
+ );
+ field_create_instance($instance);
+
drupal_set_message(t('The block has been created.'));
cache_clear_all();
$form_state['redirect'] = 'admin/structure/block';
diff --git modules/block/block.install modules/block/block.install
index 28252ed..938283b 100644
--- modules/block/block.install
+++ modules/block/block.install
@@ -18,6 +18,12 @@ function block_schema() {
'not null' => TRUE,
'description' => 'Primary Key: Unique block ID.',
),
+ 'block_id' => array(
+ 'type' => 'int',
+ 'not null' => TRUE,
+ 'default' => 0,
+ 'description' => 'Entity ID for block',
+ ),
'module' => array(
'type' => 'varchar',
'length' => 64,
@@ -168,12 +174,6 @@ function block_schema() {
'not null' => TRUE,
'description' => "The block's {block}.bid.",
),
- 'body' => array(
- 'type' => 'text',
- 'not null' => FALSE,
- 'size' => 'big',
- 'description' => 'Block contents.',
- ),
'info' => array(
'type' => 'varchar',
'length' => 128,
@@ -181,13 +181,6 @@ function block_schema() {
'default' => '',
'description' => 'Block description.',
),
- 'format' => array(
- 'type' => 'int',
- 'size' => 'small',
- 'not null' => TRUE,
- 'default' => 0,
- 'description' => "Block body's {filter_format}.format; for example, 1 = Filtered HTML.",
- )
),
'unique keys' => array(
'info' => array('info'),
@@ -274,3 +267,87 @@ function block_update_7001() {
db_create_table($ret, 'block_node_type', $schema['block_node_type']);
return $ret;
}
+
+/**
+ * Convert custom block body to a field.
+ */
+function block_update_7002() {
+ $ret = array();
+
+ // Add a block_id column that stores a theme independent entity ID for each
+ // block.
+ $block_id_field = array(
+ 'type' => 'int',
+ 'not null' => TRUE,
+ 'description' => 'Entity ID for block',
+ );
+
+ // Check that the field hasn't been updated in an aborted run of this
+ // update.
+ if (!db_column_exists('block', 'block_id')) {
+ // Add a new field for the block_id.
+ db_add_field($ret, 'block', 'block_id', $block_id_field);
+ }
+
+ $blocks = db_query('SELECT * FROM {block} ORDER BY module, delta')->execute();
+ $next_id = 1;
+ $updated_blocks = array();
+ foreach ($blocks as $block) {
+ if (!in_array($block->module . '_' . $block->delta, $updated_blocks)) {
+ db_update('block')
+ ->fields(array('block_id' => $next_id))
+ ->condition('module', $block->module)
+ ->condition('delta', $block->delta)
+ ->execute();
+ $next_id++;
+ }
+ }
+
+ // Create the 'block_body' field if it doesn't already exist.
+ $field = field_info_field('block_body');
+ if (empty($field)) {
+ $field = array(
+ 'field_name' => 'block_body',
+ 'type' => 'text_long',
+ );
+ field_create_field($field);
+ }
+
+ // Attach an instance of the 'block_body' field to all custom blocks.
+ $boxes = db_query('SELECT * FROM {box}')->execute();
+ foreach ($boxes as $box) {
+ // Create a new bundle for the block
+ field_attach_create_bundle('block_' . $box->bid);
+
+ $instance = array(
+ 'field_name' => 'block_body',
+ 'bundle' => 'block_' . $box->bid,
+ 'label' => t('Block body'),
+ 'description' => t('The content of the block as shown to the user.'),
+ 'required' => TRUE,
+ 'settings' => array('text_processing' => 1),
+ 'widget' => array(
+ 'type' => 'text_textarea',
+ 'label' => t('Block body'),
+ ),
+ 'display' => array(
+ 'full' => array('label' => 'hidden'),
+ ),
+ );
+ field_create_instance($instance);
+
+ // Move the block body to the new 'block_body' field.
+ $box->block_machine_name = 'block_' . $box->bid;
+ $box->block_body[0]['value'] = $box->body;
+ $box->block_body[0]['format'] = $box->format;
+ // This is a core update and no contrib modules are enabled yet, so we can
+ // assume default field storage for a faster update.
+ field_sql_storage_field_storage_write('block', $box, FIELD_STORAGE_INSERT, array());
+ }
+
+ // Remove the now-obsolete body info from box.
+ db_drop_field($ret, 'box', 'body');
+ db_drop_field($ret, 'box', 'format');
+
+ return $ret;
+}
diff --git modules/block/block.module modules/block/block.module
index f8b9af8..ebd6719 100644
--- modules/block/block.module
+++ modules/block/block.module
@@ -67,7 +67,7 @@ function block_help($path, $arg) {
switch ($path) {
case 'admin/help#block':
$output = '
' . t('Blocks are boxes of content rendered into an area, or region, of a web page. The default theme Garland, for example, implements the regions "left sidebar", "right sidebar", "content", "header", and "footer", and a block may appear in any one of these areas. The blocks administration page provides a drag-and-drop interface for assigning a block to a region, and for controlling the order of blocks within regions.', array('@blocks' => url('admin/structure/block'))) . '
';
- $output .= '' . t('Although blocks are usually generated automatically by modules (like the User login block, for example), administrators can also define custom blocks. Custom blocks have a title, description, and body. The body of the block can be as long as necessary, and can contain content supported by any available text format.', array('@text-format' => url('admin/settings/filter'))) . '
';
+ $output .= '' . t('Although blocks are usually generated automatically by modules (like the User login block, for example), administrators can also define custom blocks. Custom blocks have a title, description, and a body field by default with the option to add additional fields. The body of the block can be as long as necessary, and can contain content supported by any available text format.', array('@text-format' => url('admin/settings/filter'))) . '
';
$output .= '' . t('When working with blocks, remember that:') . '
';
$output .= '- ' . t('since not all themes implement the same regions, or display regions in the same way, blocks are positioned on a per-theme basis.') . '
';
$output .= '- ' . t('disabled blocks, or blocks not in a region, are never shown.') . '
';
@@ -105,6 +105,53 @@ function block_theme() {
}
/**
+ * Implement hook_entity_info().
+ */
+function block_entity_info() {
+ $return = array(
+ 'block' => array(
+ 'label' => t('Block'),
+ 'controller class' => 'DrupalDefaultEntityController',
+ 'base table' => 'block',
+ 'fieldable' => TRUE,
+ 'object keys' => array(
+ 'id' => 'block_id',
+ 'bundle' => 'block_machine_name',
+ ),
+ 'bundles' => array(),
+ ),
+ );
+
+ $blocks = db_query('SELECT block_id, module, delta FROM {block} GROUP BY block_id');
+ foreach ($blocks as $block) {
+ $return['block']['bundles'][$block->module . '_' . $block->delta] = array(
+ 'label' => $block->module . '_' . $block->delta,
+ 'admin' => array(
+ //'path' => 'admin/structure/block/configure/%',
+ 'path' => 'admin/structure/block/configure/' . $block->module . '_' . $block->delta,
+ //'real path' => 'admin/structure/block/configure/' . $block->module . '_' . $block->delta,
+ //'bundle argument' => 4,
+ 'access arguments' => array('administer blocks'),
+ ),
+ );
+ }
+ return $return;
+}
+
+/**
+ * Implement hook_field_build_modes().
+ */
+function block_field_build_modes($obj_type) {
+ $modes = array();
+ if ($obj_type == 'block') {
+ $modes = array(
+ 'full' => t('Block'),
+ );
+ }
+ return $modes;
+}
+
+/**
* Implement hook_permission().
*/
function block_permission() {
@@ -139,14 +186,19 @@ function block_menu() {
'type' => MENU_CALLBACK,
'file' => 'block.admin.inc',
);
- $items['admin/structure/block/configure'] = array(
- 'title' => 'Configure block',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('block_admin_configure'),
- 'access arguments' => array('administer blocks'),
- 'type' => MENU_CALLBACK,
- 'file' => 'block.admin.inc',
- );
+
+ $blocks = db_query('SELECT block_id, module, delta FROM {block} GROUP BY block_id');
+ foreach ($blocks as $block) {
+ $items['admin/structure/block/configure/' . $block->module . '_' . $block->delta] = array(
+ 'title' => 'Configure block',
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array('block_admin_configure', 4),
+ 'access arguments' => array('administer blocks'),
+ 'type' => MENU_CALLBACK,
+ 'file' => 'block.admin.inc',
+ );
+ }
+
$items['admin/structure/block/delete'] = array(
'title' => 'Delete block',
'page callback' => 'drupal_get_form',
@@ -220,17 +272,6 @@ function block_block_save($delta = 0, $edit = array()) {
}
/**
- * Implement hook_block_view().
- *
- * 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();
- $data['content'] = check_markup($block->body, $block->format);
- return $data;
-}
-
-/**
* Implement hook_page_alter().
*
* Render blocks into their regions.
@@ -327,8 +368,9 @@ function _block_rehash() {
// value if the module did not.
$block['pages'] = '';
}
- // Add defaults and save it into the database.
- drupal_write_record('block', $block);
+
+ $block = block_save($block);
+
// Set region to none if not enabled.
$block['region'] = $block['status'] ? $block['region'] : BLOCK_REGION_NONE;
// Add to the list of blocks we return.
@@ -362,6 +404,7 @@ function _block_rehash() {
// Remove blocks that are no longer defined by the code from the database.
foreach ($old_blocks as $module => $old_module_blocks) {
foreach ($old_module_blocks as $delta => $block) {
+ field_attach_delete_bundle($module . '_' . $delta);
db_delete('block')
->condition('module', $module)
->condition('delta', $delta)
@@ -380,10 +423,7 @@ function block_box_get($bid) {
* Define the custom block form.
*/
function block_box_form($edit = array()) {
- $edit += array(
- 'info' => '',
- 'body' => '',
- );
+ $edit += array('info' => '');
$form['info'] = array(
'#type' => 'textfield',
'#title' => t('Block description'),
@@ -393,18 +433,6 @@ function block_box_form($edit = array()) {
'#required' => TRUE,
'#weight' => -19,
);
- $form['body_field']['#weight'] = -17;
- $form['body_field']['body'] = array(
- '#type' => 'textarea',
- '#title' => t('Block body'),
- '#default_value' => $edit['body'],
- '#text_format' => isset($edit['format']) ? $edit['format'] : FILTER_FORMAT_DEFAULT,
- '#rows' => 15,
- '#description' => t('The content of the block as shown to the user.'),
- '#required' => TRUE,
- '#weight' => -17,
- '#access' => filter_access($edit['format']),
- );
return $form;
}
@@ -412,9 +440,7 @@ function block_box_form($edit = array()) {
function block_box_save($edit, $delta) {
db_update('box')
->fields(array(
- 'body' => $edit['body'],
'info' => $edit['info'],
- 'format' => $edit['body_format'],
))
->condition('bid', $delta)
->execute();
@@ -521,7 +547,7 @@ function block_theme_initialize($theme) {
}
$block['theme'] = $theme;
unset($block['bid']);
- drupal_write_record('block', $block);
+ block_save($block);
}
}
}
@@ -560,6 +586,44 @@ function block_list($region) {
}
/**
+ * Save a block to the database.
+ *
+ * Field API requires each entity to have a unique, numeric, entity ID. If this
+ * is a new block generate a unique block_id, if this is a block that already
+ * exists in another theme reuse the old block_id.
+ *
+ * @param $block
+ * An associative array of fields that will be saved to the block table.
+ * @return
+ * The $block array, in the case of a new block both the bid, and block_id
+ * fields will have been added.
+ */
+function block_save($block) {
+ // Every block needs an entity ID that is the same regardless of the theme.
+ if (!isset($block['block_id'])) {
+ // Check to see if the module/delta combination already has a block_id.
+ $block_id = db_query('SELECT block_id FROM {block} WHERE module = :module AND delta = :delta LIMIT 1', array(':module' => $block['module'], ':delta' => $block['delta']))->fetchField();
+ if (!$block_id) {
+ $previous_block_id = db_query("SELECT block_id FROM {block} ORDER BY block_id DESC LIMIT 1")->fetchField();
+ $previous_block_id = (isset($previous_block_id)) ? $previous_block_id : 0;
+ $block_id = $previous_block_id + 1;
+ }
+ $block['block_id'] = $block_id;
+ $is_new = TRUE;
+ }
+
+ // Add defaults and save it into the database.
+ drupal_write_record('block', $block);
+
+ // Create a Field API bundle for the block.
+ if (isset($is_new)) {
+ field_attach_create_bundle($block['module'] . '_' . $block['delta']);
+ }
+
+ return $block;
+}
+
+/**
* Load blocks information from the database.
*/
function _block_load_blocks() {
@@ -735,11 +799,20 @@ function _block_render_blocks($region_blocks) {
$block->$k = $v;
}
}
- if (isset($block->content) && $block->content) {
- // Normalize to the drupal_render() structure.
- if (is_string($block->content)) {
- $block->content = array('#markup' => $block->content);
- }
+
+ // Attach fields.
+ $block->block_machine_name = $block->module . '_' . $block->delta;
+ field_attach_load('block', array($block->block_id => $block));
+ // Normalize to the drupal_render() structure.
+ if (isset($block->content) && is_string($block->content)) {
+ $block->content = array('#markup' => $block->content);
+ }
+ else if (empty($block->content)) {
+ $block->content = array();
+ }
+ $block->content += field_attach_view('block', $block, 'full');
+
+ if (!empty($block->content['#markup']) || element_children($block->content)) {
// Override default block title if a custom display title is present.
if ($block->title) {
// Check plain here to allow module generated titles to keep any
@@ -852,14 +925,3 @@ function template_preprocess_block(&$variables) {
$variables['template_files'][] = 'block-' . $variables['block']->module;
$variables['template_files'][] = 'block-' . $variables['block']->module . '-' . $variables['block']->delta;
}
-
-/**
- * Implement hook_filter_format_delete().
- */
-function block_filter_format_delete($format, $default) {
- db_update('box')
- ->fields(array('format' => $default->format))
- ->condition('format', $format->format)
- ->execute();
-}
-
diff --git modules/block/block.test modules/block/block.test
index e2f4d19..783b891 100644
--- modules/block/block.test
+++ modules/block/block.test
@@ -41,7 +41,6 @@ class BlockTestCase extends DrupalWebTestCase {
$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'));
// Confirm that the box has been created, and then query the created bid.
@@ -73,12 +72,16 @@ class BlockTestCase extends DrupalWebTestCase {
$box = array();
$box['info'] = $this->randomName(8);
$box['title'] = $this->randomName(8);
- $box['body'] = 'Full HTML
';
- $box['body_format'] = 2;
$this->drupalPost('admin/structure/block/add', $box, t('Save block'));
- // Set the created box to a specific region.
+ // Fill in the block_body field.
$bid = db_query("SELECT bid FROM {box} WHERE info = :info", array(':info' => $box['info']))->fetchField();
+ $box = array();
+ $box['block_body[' . FIELD_LANGUAGE_NONE . '][0][value]'] = 'Full HTML
';
+ $box['block_body[' . FIELD_LANGUAGE_NONE . '][0][value_format]'] = 2;
+ $this->drupalPost('admin/structure/block/configure/block_' . $bid, $box, t('Save block'));
+
+ // Set the created box to a specific region.
$edit = array();
$edit['block_' . $bid . '[region]'] = $this->regions[1]['name'];
$this->drupalPost('admin/structure/block', $edit, t('Save blocks'));
@@ -90,9 +93,9 @@ class BlockTestCase extends DrupalWebTestCase {
// but can still submit the form without errors.
$block_admin = $this->drupalCreateUser(array('administer blocks'));
$this->drupalLogin($block_admin);
- $this->drupalGet('admin/structure/block/configure/block/' . $bid);
+ $this->drupalGet('admin/structure/block/configure/block_' . $bid);
$this->assertNoText(t('Block body'));
- $this->drupalPost('admin/structure/block/configure/block/' . $bid, array(), t('Save block'));
+ $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.
@@ -112,7 +115,6 @@ class BlockTestCase extends DrupalWebTestCase {
$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'));
$bid = db_query("SELECT bid FROM {box} WHERE info = :info", array(':info' => $box['info']))->fetchField();
@@ -123,9 +125,10 @@ class BlockTestCase extends DrupalWebTestCase {
// Set the block to be hidden on any user path, and to be shown only to
// authenticated users.
$edit = array();
+ $edit['block_body[' . FIELD_LANGUAGE_NONE . '][0][value]'] = $this->randomName(32);
$edit['pages'] = 'user*';
$edit['roles[2]'] = TRUE;
- $this->drupalPost('admin/structure/block/configure/' . $block['module'] . '/' . $block['delta'], $edit, t('Save block'));
+ $this->drupalPost('admin/structure/block/configure/' . $block['module'] . '_' . $block['delta'], $edit, t('Save block'));
// Move block to the first sidebar.
$this->moveBlockToRegion($block, $this->regions[1]);
@@ -153,7 +156,7 @@ class BlockTestCase extends DrupalWebTestCase {
$block['title'] = $this->randomName(8);
// Set block title to confirm that interface works and override any custom titles.
- $this->drupalPost('admin/structure/block/configure/' . $block['module'] . '/' . $block['delta'], array('title' => $block['title']), t('Save block'));
+ $this->drupalPost('admin/structure/block/configure/' . $block['module'] . '_' . $block['delta'], array('title' => $block['title']), t('Save block'));
$this->assertText(t('The block configuration has been saved.'), t('Block title set.'));
$bid = db_query("SELECT bid FROM {block} WHERE module = :module AND delta = :delta", array(
':module' => $block['module'],
@@ -187,7 +190,7 @@ class BlockTestCase extends DrupalWebTestCase {
$this->drupalPost('admin/structure/block', $edit, t('Save blocks'));
$this->assertText(t('The block settings have been updated.'), t('Block successfully move to first sidebar region.'));
- $this->drupalPost('admin/structure/block/configure/' . $block['module'] . '/' . $block['delta'], array('title' => 'Navigation'), t('Save block'));
+ $this->drupalPost('admin/structure/block/configure/' . $block['module'] . '_' . $block['delta'], array('title' => 'Navigation'), t('Save block'));
$this->assertText(t('The block configuration has been saved.'), t('Block title set.'));
}
diff --git modules/comment/comment.test modules/comment/comment.test
index 663dd9d..e5528ca 100644
--- modules/comment/comment.test
+++ modules/comment/comment.test
@@ -738,7 +738,7 @@ class CommentBlockFunctionalTest extends CommentHelperCase {
'title' => $this->randomName(),
'comment_block_count' => 2,
);
- $this->drupalPost('admin/structure/block/configure/comment/recent', $block, t('Save block'));
+ $this->drupalPost('admin/structure/block/configure/comment_recent', $block, t('Save block'));
$this->assertText(t('The block configuration has been saved.'), t('Block saved.'));
// Add some test comments, one without a subject.
@@ -767,7 +767,7 @@ class CommentBlockFunctionalTest extends CommentHelperCase {
$block = array(
'comment_block_count' => 10,
);
- $this->drupalPost('admin/structure/block/configure/comment/recent', $block, t('Save block'));
+ $this->drupalPost('admin/structure/block/configure/comment_recent', $block, t('Save block'));
$this->assertText(t('The block configuration has been saved.'), t('Block saved.'));
// Post an additional comment.
diff --git modules/filter/filter.test modules/filter/filter.test
index 6c932c6..720c0a7 100644
--- modules/filter/filter.test
+++ modules/filter/filter.test
@@ -760,8 +760,8 @@ class FilterHooksTestCase extends DrupalWebTestCase {
}
function setUp() {
- parent::setUp('block', 'filter_test');
- $admin_user = $this->drupalCreateUser(array('administer filters', 'administer blocks'));
+ parent::setUp('filter_test');
+ $admin_user = $this->drupalCreateUser(array('administer filters'));
$this->drupalLogin($admin_user);
}
@@ -787,33 +787,10 @@ class FilterHooksTestCase extends DrupalWebTestCase {
$this->assertRaw(t('The text format settings have been updated.'), t('Full HTML format successfully updated.'));
$this->assertText(t('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);
- // Use the format created.
- $box['body_format'] = $format;
- $this->drupalPost('admin/structure/block/add', $box, 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();
- $this->assertNotNull($bid, t('New block found in database'));
-
// Delete the text format.
$this->drupalPost('admin/settings/formats/' . $format . '/delete', array(), t('Delete'));
$this->assertRaw(t('Deleted text format %format.', array('%format' => $name)), t('Format successfully deleted.'));
$this->assertText(t('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')
- ->fields('b', array('format'))
- ->condition('bid', $bid)
- ->execute()
- ->fetchField();
- $default = variable_get('filter_default_format', 1);
- $this->assertEqual($current_format, $default, t('Deleted text format replaced with the default format.'));
}
}
diff --git profiles/default/default.install profiles/default/default.install
index bd235c6..88d24fb 100644
--- profiles/default/default.install
+++ profiles/default/default.install
@@ -9,7 +9,7 @@
function default_install() {
// Enable some standard blocks.
- $values = array(
+ $blocks = array(
array(
'module' => 'system',
'delta' => 'main',
@@ -101,11 +101,10 @@ function default_install() {
'cache' => -1,
),
);
- $query = db_insert('block')->fields(array('module', 'delta', 'theme', 'status', 'weight', 'region', 'pages', 'cache'));
- foreach ($values as $record) {
- $query->values($record);
+
+ foreach ($blocks as $block) {
+ block_save($block);
}
- $query->execute();
// Insert default user-defined node types into the database. For a complete
// list of available node type attributes, refer to the node type API
diff --git profiles/expert/expert.install profiles/expert/expert.install
index 750ebe1..485054f 100644
--- profiles/expert/expert.install
+++ profiles/expert/expert.install
@@ -9,7 +9,7 @@
function expert_install() {
// Enable some standard blocks.
- $values = array(
+ $blocks = array(
array(
'module' => 'system',
'delta' => 'main',
@@ -61,11 +61,10 @@ function expert_install() {
'cache' => -1,
),
);
- $query = db_insert('block')->fields(array('module', 'delta', 'theme', 'status', 'weight', 'region', 'pages', 'cache'));
- foreach ($values as $record) {
- $query->values($record);
+
+ foreach ($blocks as $block) {
+ block_save($block);
}
- $query->execute();
}