diff --git modules/block/block.admin.inc modules/block/block.admin.inc
index f771cd9..4c82c20 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['block_id']),
);
if ($block['module'] == 'block') {
$form[$key]['delete'] = array(
@@ -179,32 +179,33 @@ 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, $block) {
$form['module'] = array(
'#type' => 'value',
- '#value' => $module,
+ '#value' => $block->module,
);
$form['delta'] = array(
'#type' => 'value',
- '#value' => $delta,
+ '#value' => $block->delta,
);
- $edit = db_query("SELECT pages, visibility, custom, title FROM {block} WHERE module = :module AND delta = :delta", array(
- ':module' => $module,
- ':delta' => $delta,
- ))->fetchAssoc();
+ $form['block_id'] = array(
+ '#type' => 'value',
+ '#value' => (isset($block->block_id)) ? $block->block_id : '',
+ );
$form['block_settings'] = array(
'#type' => 'fieldset',
'#title' => t('Block specific settings'),
'#collapsible' => TRUE,
+ '#weight' => field_attach_extra_weight($block->block_machine_name, 'block_settings'),
);
$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'],
+ '#description' => $block->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' => (isset($block->title)) ? $block->title : '',
'#weight' => -18,
);
@@ -216,6 +217,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' => field_attach_extra_weight($block->block_machine_name, 'regions'),
);
$theme_default = variable_get('theme_default', 'garland');
@@ -225,8 +227,8 @@ function block_admin_configure(&$form_state, $module = NULL, $delta = 0) {
// Only display enabled themes
if ($theme->status) {
$region = db_query("SELECT region FROM {block} WHERE module = :module AND delta = :delta AND theme = :theme", array(
- ':module' => $module,
- ':delta' => $delta,
+ ':module' => $block->module,
+ ':delta' => $block->delta,
':theme' => $theme_key,
))->fetchField();
@@ -242,16 +244,22 @@ function block_admin_configure(&$form_state, $module = NULL, $delta = 0) {
}
// Module-specific block configurations.
- if ($settings = module_invoke($module, 'block_configure', $delta)) {
+ if ($settings = module_invoke($block->module, 'block_configure', $block->delta)) {
foreach ($settings as $k => $v) {
$form['block_settings'][$k] = $v;
}
}
// Get the block subject for the page title.
- $info = module_invoke($module, 'block_info');
- if (isset($info[$delta])) {
- drupal_set_title(t("'%name' block", array('%name' => $info[$delta]['info'])), PASS_THROUGH);
+ $info = module_invoke($block->module, 'block_info');
+ if (isset($info[$block->delta])) {
+ drupal_set_title(t("'%name' block", array('%name' => $info[$block->delta]['info'])), PASS_THROUGH);
+ }
+
+ // Attach fields.
+ if (isset($block->block_id)) {
+ field_attach_load('block', array($block->block_id => $block));
+ field_attach_form('block', $block, $form, $form_state);
}
$form['page_vis_settings'] = array(
@@ -259,13 +267,14 @@ function block_admin_configure(&$form_state, $module = NULL, $delta = 0) {
'#title' => t('Page specific visibility settings'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
+ '#weight' => field_attach_extra_weight($block->block_machine_name, 'page_vis_settings'),
);
$access = user_access('use PHP for settings');
- if ($edit['visibility'] == 2 && !$access) {
+ if (isset($block->visibility) && $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' => (isset($block->pages)) ? $block->pages : '');
}
else {
$options = array(t('Every page except those specified below.'), t('Only the pages specified below.'));
@@ -279,20 +288,20 @@ 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' => (isset($block->visibility)) ? $block->visibility : '',
);
$form['page_vis_settings']['pages'] = array(
'#type' => 'textarea',
'#title' => t('Pages'),
- '#default_value' => $edit['pages'],
+ '#default_value' => (isset($block->pages)) ? $block->pages : '',
'#description' => $description,
);
}
// Role-based visibility settings.
$default_role_options = db_query("SELECT rid FROM {block_role} WHERE module = :module AND delta = :delta", array(
- ':module' => $module,
- ':delta' => $delta,
+ ':module' => $block->module,
+ ':delta' => $block->delta,
))->fetchCol();
$role_options = db_query('SELECT rid, name FROM {role} ORDER BY name')->fetchAllKeyed();
$form['role_vis_settings'] = array(
@@ -300,6 +309,7 @@ function block_admin_configure(&$form_state, $module = NULL, $delta = 0) {
'#title' => t('Role specific visibility settings'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
+ '#weight' => field_attach_extra_weight($block->block_machine_name, 'role_vis_settings'),
);
$form['role_vis_settings']['roles'] = array(
'#type' => 'checkboxes',
@@ -311,14 +321,15 @@ function block_admin_configure(&$form_state, $module = NULL, $delta = 0) {
// Content type specific configuration.
$default_type_options = db_query("SELECT type FROM {block_node_type} WHERE module = :module AND delta = :delta", array(
- ':module' => $module,
- ':delta' => $delta,
+ ':module' => $block->module,
+ ':delta' => $block->delta,
))->fetchCol();
$form['content_type_vis_settings'] = array(
'#type' => 'fieldset',
'#title' => t('Content type specific visibility settings'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
+ '#weight' => field_attach_extra_weight($block->block_machine_name, 'content_type_vis_settings'),
);
$form['content_type_vis_settings']['types'] = array(
'#type' => 'checkboxes',
@@ -334,6 +345,7 @@ function block_admin_configure(&$form_state, $module = NULL, $delta = 0) {
'#title' => t('User specific visibility settings'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
+ '#weight' => field_attach_extra_weight($block->block_machine_name, 'user_vis_settings'),
);
$form['user_vis_settings']['custom'] = array(
'#type' => 'radios',
@@ -344,12 +356,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' => (isset($block->custom)) ? $block->custom : '',
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save block'),
+ '#weight' => 99,
);
return $form;
@@ -365,10 +378,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'],
@@ -411,7 +432,7 @@ function block_admin_configure_submit($form, &$form_state) {
// Store regions per theme for this block
foreach ($form_state['values']['regions'] as $theme => $region) {
db_merge('block')
- ->key(array('theme' => $theme, 'delta' => $form_state['values']['delta'], 'module' => $form_state['values']['module']))
+ ->key(array('block_id' => $block->block_id, 'theme' => $theme, 'delta' => $form_state['values']['delta'], 'module' => $form_state['values']['module']))
->fields(array(
'region' => $region,
'pages' => trim($form_state['values']['pages']),
@@ -420,6 +441,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 +454,23 @@ 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);
+ $block = array(
+ 'block_machine_name' => 'block_0',
+ 'module' => 'block',
+ 'delta' => 0
+ );
+ $form = block_admin_configure($form_state, (object) $block);
+ // When creating a new custom block the Field API bundle for the block and
+ // block_body field have not been created yet. Collect input for the
+ // block_body field here and place it in the new Field API field once it has
+ // been created.
+ $form['block_body'] = array(
+ '#type' => 'textarea',
+ '#title' => t('Block body'),
+ '#text_format' => FILTER_FORMAT_DEFAULT,
+ '#required' => TRUE,
+ );
+ return $form;
}
function block_add_block_form_validate($form, &$form_state) {
@@ -448,30 +487,30 @@ function block_add_block_form_validate($form, &$form_state) {
function block_add_block_form_submit($form, &$form_state) {
$delta = db_insert('block_custom')
->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' => DRUPAL_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' => DRUPAL_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) {
@@ -505,6 +544,41 @@ function block_add_block_form_submit($form, &$form_state) {
->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);
+
+ // Move the content from the temporary block_body field to the new Field API
+ // block_body field.
+ $block['block_machine_name'] = 'block:' . $delta;
+ $block['block_body'][FIELD_LANGUAGE_NONE][0]['value'] = $form_state['values']['block_body'];
+ $block['block_body'][FIELD_LANGUAGE_NONE][0]['format'] = $form_state['values']['block_body_format'];
+ field_attach_insert('block', (object) $block);
+
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 7311d40..6c0f469 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'),
@@ -221,6 +214,7 @@ function block_install() {
*/
function block_uninstall() {
drupal_uninstall_schema('block');
+ variable_del('block_id_sequence');
}
/**
@@ -274,3 +268,91 @@ 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,
+ 'initial' => 0,
+ '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}');
+ $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++;
+ $updated_blocks[] = $block->module . '_' . $block->delta;
+ }
+ }
+
+ // 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 bx.*, b.block_id FROM {box} bx INNER JOIN {block} b ON b.delta = bx.bid GROUP BY bx.bid');
+ 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[FIELD_LANGUAGE_NONE][0]['value'] = $box->body;
+ unset($box->body);
+ $box->block_body[FIELD_LANGUAGE_NONE][0]['format'] = $box->format;
+ unset($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 3ba83ce..051e3b4 100644
--- modules/block/block.module
+++ modules/block/block.module
@@ -18,7 +18,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.') . '
';
@@ -56,6 +56,92 @@ function block_theme() {
}
/**
+ * Implement hook_entity_info().
+ */
+function block_entity_info() {
+ $return = array(
+ 'block' => array(
+ 'label' => t('Block'),
+ 'controller class' => 'BlockController',
+ 'base table' => 'block',
+ 'fieldable' => TRUE,
+ 'object keys' => array(
+ 'id' => 'block_id',
+ 'bundle' => 'block_machine_name',
+ ),
+ 'bundle keys' => array(
+ '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/%block',
+ 'real path' => 'admin/structure/block/configure/' . $block->block_id,
+ '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_field_extra_fields().
+ */
+function block_field_extra_fields($bundle) {
+ $extra = array();
+ $extra['block_settings'] = array(
+ 'label' => t('Block settings'),
+ 'description' => t('Block specific settings'),
+ 'weight' => -10,
+ );
+ $extra['regions'] = array(
+ 'label' => t('Region settings'),
+ 'description' => t('Specify in which region this block is displayed.'),
+ 'weight' => 30,
+ );
+ $extra['page_vis_settings'] = array(
+ 'label' => t('Page visibility settings'),
+ 'description' => t('Page specific visibility settings'),
+ 'weight' => 31,
+ );
+ $extra['role_vis_settings'] = array(
+ 'label' => t('Role visibility settings'),
+ 'description' => t('Role specific visibility settings'),
+ 'weight' => 32,
+ );
+ $extra['content_type_vis_settings'] = array(
+ 'label' => t('Content type visibility settings'),
+ 'description' => t('Show block for specific content types'),
+ 'weight' => 33,
+ );
+ $extra['user_vis_settings'] = array(
+ 'label' => t('User visibility settings'),
+ 'description' => t('User specific visibility settings'),
+ 'weight' => 34,
+ );
+ return $extra;
+}
+
+/**
* Implement hook_permission().
*/
function block_permission() {
@@ -90,10 +176,10 @@ function block_menu() {
'type' => MENU_CALLBACK,
'file' => 'block.admin.inc',
);
- $items['admin/structure/block/configure'] = array(
+ $items['admin/structure/block/configure/%block'] = array(
'title' => 'Configure block',
'page callback' => 'drupal_get_form',
- 'page arguments' => array('block_admin_configure'),
+ 'page arguments' => array('block_admin_configure', 4),
'access arguments' => array('administer blocks'),
'type' => MENU_CALLBACK,
'file' => 'block.admin.inc',
@@ -171,17 +257,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 {block_custom} 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.
@@ -218,6 +293,36 @@ function block_page_build(&$page) {
}
/**
+ * Implement hook_modules_enabled().
+ *
+ * When a new module that provides a block is enabled we need to make sure that
+ * block_save() is called for each new block so that the block is assigned a
+ * block_id.
+ */
+function block_modules_enabled($modules) {
+ $blocks = array();
+ foreach ($modules as $module_name) {
+ $function = $module_name . '_block_info';
+ if (function_exists($function)) {
+ $blocks = $function();
+ foreach ($blocks as $delta => $block) {
+ // Check to see if the block already exists in the database.
+ $old_block = db_query('SELECT 1 FROM {block} WHERE module = :module AND delta = :delta', array(':module' => $module_name, ':delta' => $delta))->fetchObject();
+ // If the block does not exist in the database save it now so that the
+ // block_id is generated.
+ if ($old_block !== FALSE) {
+ $block['module'] = $module_name;
+ $block['delta'] = $delta;
+ $block['theme'] = variable_get('theme_default', 'garland');
+ $block['pages'] = (isset($block['pages'])) ? $block['pages'] : '';
+ block_save($block);
+ }
+ }
+ }
+ }
+}
+
+/**
* Get a renderable array of a region containing all enabled blocks.
*
* @param $region
@@ -278,8 +383,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.
@@ -313,6 +419,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)
@@ -333,7 +440,6 @@ function block_custom_block_get($bid) {
function block_custom_block_form($edit = array()) {
$edit += array(
'info' => '',
- 'body' => '',
);
$form['info'] = array(
'#type' => 'textfield',
@@ -344,18 +450,6 @@ function block_custom_block_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;
}
@@ -363,9 +457,7 @@ function block_custom_block_form($edit = array()) {
function block_custom_block_save($edit, $delta) {
db_update('block_custom')
->fields(array(
- 'body' => $edit['body'],
'info' => $edit['info'],
- 'format' => $edit['body_format'],
))
->condition('bid', $delta)
->execute();
@@ -472,7 +564,7 @@ function block_theme_initialize($theme) {
}
$block['theme'] = $theme;
unset($block['bid']);
- drupal_write_record('block', $block);
+ block_save($block);
}
}
}
@@ -511,6 +603,109 @@ function block_list($region) {
}
/**
+ * Given a module and delta return the entity ID for a block.
+ *
+ * @param $module
+ * Name of the module that implements the block.
+ * @param $delta
+ * Unique ID of the block within the defining module.
+ *
+ * @return
+ * The numeric entity ID of the block or FALSE if there is no matching block.
+ * Resuts are statically cached.
+ */
+function block_entity_id($module, $delta) {
+ $block_ids = &drupal_static(__FUNCTION__, array());
+
+ if (isset($block_ids[$module . '_' . $delta])) {
+ return $block_ids[$module . '_' . $delta];
+ }
+
+ $id = db_query('SELECT block_id FROM {block} WHERE module = :module AND delta = :delta LIMIT 1', array(':module' => $module, ':delta' => $delta))->fetchField();
+ if ($id) {
+ $block_ids[$module . '_' . $delta] = $id;
+ return $id;
+ }
+
+ return FALSE;
+}
+
+/**
+ * Return the block object matching the module and delta.
+ *
+ * @param $block_id
+ * The block_id of the block to load.
+ *
+ * @return
+ * A block object.
+ */
+function block_load($block_id) {
+ $block = block_load_multiple(array($block_id));
+ return $block ? $block[$block_id] : FALSE;
+}
+
+/**
+ * Load block entities from the database.
+ *
+ * This function should be used whenever you need to load more than one block
+ * from the database. Blocks are loaded into memory and will not require
+ * database access if loaded again during the same page request.
+ *
+ * @see entity_load()
+ *
+ * @param $block_ids
+ * An array of block IDs.
+ * @param $conditions
+ * An array of conditions on the {block} table in the form 'field' => $value.
+ * @param $reset
+ * Whether to reset the internal block_load cache.
+ *
+ * @return
+ * An array of block objects indexed by block_id.
+ */
+function block_load_multiple($block_ids = array(), $conditions = array(), $reset = FALSE) {
+ return entity_load('block', $block_ids, $conditions, $reset);
+}
+
+/**
+ * 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 = ($previous_block_id) ? $previous_block_id : 1;
+ $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() {
@@ -686,11 +881,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
@@ -796,12 +1000,16 @@ function block_user_role_delete($role) {
}
/**
- * Implement hook_filter_format_delete().
+ * Controller class for blocks.
+ *
+ * This extends the DrupalDefaultEntityController class, adding required
+ * special handling for block objects.
*/
-function block_filter_format_delete($format, $default) {
- db_update('block_custom')
- ->fields(array('format' => $default->format))
- ->condition('format', $format->format)
- ->execute();
+class BlockController extends DrupalDefaultEntityController {
+ protected function attachLoad(&$blocks) {
+ foreach ($blocks as $block_id => $block) {
+ $blocks[$block_id]->block_machine_name = $block->module . ':' . $block->delta;
+ }
+ parent::attachLoad($blocks);
+ }
}
-
diff --git modules/block/block.test modules/block/block.test
index c3f6094..192bc7d 100644
--- modules/block/block.test
+++ modules/block/block.test
@@ -41,7 +41,7 @@ class BlockTestCase extends DrupalWebTestCase {
$custom_block = array();
$custom_block['info'] = $this->randomName(8);
$custom_block['title'] = $this->randomName(8);
- $custom_block['body'] = $this->randomName(32);
+ $custom_block['block_body'] = $this->randomName(32);
$this->drupalPost('admin/structure/block/add', $custom_block, t('Save block'));
// Confirm that the custom block has been created, and then query the created bid.
@@ -69,12 +69,13 @@ class BlockTestCase extends DrupalWebTestCase {
* Test creating custom block using Full HTML.
*/
function testCustomBlockFormat() {
- // Add a new custom block by filling out the input form on the admin/structure/block/add page.
+ // 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'] = 'Full HTML
';
- $custom_block['body_format'] = 2;
+ $custom_block['block_body'] = 'Full HTML
';
+ $custom_block['block_body_format'] = 2;
$this->drupalPost('admin/structure/block/add', $custom_block, t('Save block'));
// Set the created custom block to a specific region.
@@ -90,9 +91,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_entity_id('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_entity_id('block', $bid), array(), t('Save block'));
$this->assertNoText(t('Please ensure that each block description is unique.'));
// Confirm that the custom block is still being displayed using configured text format.
@@ -105,14 +106,15 @@ class BlockTestCase extends DrupalWebTestCase {
function testBlockVisibility() {
$block = array();
- // Create a random title for the block
+ // Create a random title and body for the block.
$title = $this->randomName(8);
+ $body = $this->randomName(32);
// Create the custom block
$custom_block = array();
$custom_block['info'] = $this->randomName(8);
$custom_block['title'] = $title;
- $custom_block['body'] = $this->randomName(32);
+ $custom_block['block_body'] = $body;
$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();
@@ -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]'] = $body;
$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_entity_id($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_entity_id($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_entity_id($block['module'], $block['delta']), array('title' => 'Navigation'), t('Save block'));
$this->assertText(t('The block configuration has been saved.'), t('Block title set.'));
}
@@ -256,6 +259,8 @@ class NewDefaultThemeBlocks extends DrupalWebTestCase {
$this->drupalLogin($admin_user);
// Ensure no other theme's blocks are in the block table yet.
+ $res = db_query("SELECT * FROM {block} WHERE theme NOT IN ('garland', 'seven')");
+ foreach ($res as $r) { debug($r); }
$count = db_query_range("SELECT 1 FROM {block} WHERE theme NOT IN ('garland', 'seven')", 0, 1)->fetchField();
$this->assertFalse($count, t('Only Garland and Seven have blocks.'));
diff --git modules/book/book.test modules/book/book.test
index 197e4ff..1b332c4 100644
--- modules/book/book.test
+++ modules/book/book.test
@@ -215,7 +215,7 @@ class BookBlockTestCase extends DrupalWebTestCase {
function testBookNavigationBlock() {
// Set block title to confirm that the interface is availble.
- $this->drupalPost('admin/structure/block/configure/book/navigation', array('title' => $this->randomName(8)), t('Save block'));
+ $this->drupalPost('admin/structure/block/configure/' . block_entity_id('book', 'navigation'), 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.
diff --git modules/comment/comment.test modules/comment/comment.test
index 663dd9d..40ec974 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/' . block_entity_id('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/' . block_entity_id('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 34a289f..55be4ba 100644
--- modules/filter/filter.test
+++ modules/filter/filter.test
@@ -777,8 +777,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);
}
@@ -804,33 +804,10 @@ class FilterHooksTestCase extends DrupalWebTestCase {
$this->assertRaw(t('The text format settings have been updated.'), t('Full HTML format successfully updated.'));
$this->assertText('hook_filter_format_update invoked.', t('hook_filter_format_update() was invoked.'));
- // Add a new custom block.
- $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.
- $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 {block_custom} WHERE info = :info", array(':info' => $custom_block['info']))->fetchField();
- $this->assertNotNull($bid, t('New block found in database'));
-
// Delete the text format.
$this->drupalPost('admin/config/content/formats/' . $format . '/delete', array(), t('Delete'));
$this->assertRaw(t('Deleted text format %format.', array('%format' => $name)), t('Format successfully deleted.'));
$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('block_custom', '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 modules/node/node.test modules/node/node.test
index 045707f..4a5ca8a 100644
--- modules/node/node.test
+++ modules/node/node.test
@@ -484,7 +484,7 @@ class NodeBlockTestCase extends DrupalWebTestCase {
function testSearchFormBlock() {
// Set block title to confirm that the interface is availble.
- $this->drupalPost('admin/structure/block/configure/node/syndicate', array('title' => $this->randomName(8)), t('Save block'));
+ $this->drupalPost('admin/structure/block/configure/' . block_entity_id('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.
diff --git modules/poll/poll.test modules/poll/poll.test
index 0a2942d..92fdd07 100644
--- modules/poll/poll.test
+++ modules/poll/poll.test
@@ -259,7 +259,7 @@ class PollBlockTestCase extends PollTestCase {
function testRecentBlock() {
// Set block title to confirm that the interface is available.
- $this->drupalPost('admin/structure/block/configure/poll/recent', array('title' => $this->randomName(8)), t('Save block'));
+ $this->drupalPost('admin/structure/block/configure/' . block_entity_id('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 available.
diff --git modules/profile/profile.test modules/profile/profile.test
index d03e57b..264fe82 100644
--- modules/profile/profile.test
+++ modules/profile/profile.test
@@ -314,7 +314,7 @@ class ProfileBlockTestCase extends DrupalWebTestCase {
function testAuthorInformationBlock() {
// Set block title to confirm that the interface is availble.
- $this->drupalPost('admin/structure/block/configure/profile/author-information', array('title' => $this->randomName(8)), t('Save block'));
+ $this->drupalPost('admin/structure/block/configure/' . block_entity_id('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.
diff --git modules/search/search.test modules/search/search.test
index 7004142..822a599 100644
--- modules/search/search.test
+++ modules/search/search.test
@@ -404,7 +404,7 @@ class SearchBlockTestCase extends DrupalWebTestCase {
function testSearchFormBlock() {
// Set block title to confirm that the interface is availble.
- $this->drupalPost('admin/structure/block/configure/search/form', array('title' => $this->randomName(8)), t('Save block'));
+ $this->drupalPost('admin/structure/block/configure/' . block_entity_id('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.
@@ -434,7 +434,7 @@ class SearchBlockTestCase extends DrupalWebTestCase {
// Test a search from the block when it doesn't appear on the search page.
$edit = array('pages' => 'search');
- $this->drupalPost('admin/structure/block/configure/search/form', $edit, t('Save block'));
+ $this->drupalPost('admin/structure/block/configure/' . block_entity_id('search', 'form'), $edit, t('Save block'));
$this->drupalPost('node', $terms, t('Search'));
$this->assertText('Your search yielded no results');
}
diff --git modules/system/system.install modules/system/system.install
index 8eded30..188b78c 100644
--- modules/system/system.install
+++ modules/system/system.install
@@ -2045,7 +2045,7 @@ function system_update_7021() {
// 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)");
}
- drupal_set_message('The contact form information setting was migrated to a custom block and set up to only show on the site-wide contact page. The block was set to use the default text format, which might differ from the HTML based format used before. Please check the block and ensure that the output is right.');
+ drupal_set_message('The contact form information setting was migrated to a custom block and set up to only show on the site-wide contact page. The block was set to use the default text format, which might differ from the HTML based format used before. Please check the block and ensure that the output is right.');
}
// Migrate user help setting.
@@ -2055,7 +2055,7 @@ function system_update_7021() {
// 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)");
}
- drupal_set_message('The user registration guidelines were migrated to a custom block and set up to only show on the user registration page. The block was set to use the default text format, which might differ from the HTML based format used before. Please check the block and ensure that the output is right.');
+ drupal_set_message('The user registration guidelines were migrated to a custom block and set up to only show on the user registration page. The block was set to use the default text format, which might differ from the HTML based format used before. Please check the block and ensure that the output is right.');
}
// Migrate site mission setting.
@@ -2065,7 +2065,7 @@ function system_update_7021() {
// 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, '', -1)");
}
- drupal_set_message('The site mission was migrated to a custom block and set up to only show on the front page in the highlighted content region. The block was set to use the default text format, which might differ from the HTML based format used before. Please check the block and ensure that the output is right. If your theme does not have a highlighted content region, you might need to relocate the block.');
+ drupal_set_message('The site mission was migrated to a custom block and set up to only show on the front page in the highlighted content region. The block was set to use the default text format, which might differ from the HTML based format used before. Please check the block and ensure that the output is right. If your theme does not have a highlighted content region, you might need to relocate the block.');
// Migrate mission to RSS site description.
variable_set('feed_description', $mission);
}
@@ -2079,7 +2079,7 @@ function system_update_7021() {
// before the other blocks).
$ret[] = update_sql("INSERT INTO {block} (module, delta, theme, status, weight, region, pages, cache) VALUES ('block', '" . $bid . "', '" . $theme . "', 1, -10, 'footer', '', -1)");
}
- drupal_set_message('The footer message was migrated to a custom block and set up to appear in the footer. The block was set to use the default text format, which might differ from the HTML based format used before. Please check the block and ensure that the output is right. If your theme does not have a footer region, you might need to relocate the block.');
+ drupal_set_message('The footer message was migrated to a custom block and set up to appear in the footer. The block was set to use the default text format, which might differ from the HTML based format used before. Please check the block and ensure that the output is right. If your theme does not have a footer region, you might need to relocate the block.');
}
// Remove the variables (even if they were saved empty on the admin interface),
diff --git modules/system/system.module modules/system/system.module
index 7cf13bd..546cda5 100644
--- modules/system/system.module
+++ modules/system/system.module
@@ -124,7 +124,7 @@ function system_help($path, $arg) {
case 'admin/config/modules/uninstall':
return '' . t('The uninstall process removes all data related to a module. To uninstall a module, you must first disable it on the main modules page. Not all modules support this feature.', array('@modules' => url('admin/config/modules'))) . '
';
case 'admin/structure/block/configure':
- if ($arg[4] == 'system' && $arg[5] == 'powered-by') {
+ if ($arg[4] == 'system_powered-by') {
return '' . t('The Powered by Drupal block is an optional link to the home page of the Drupal project. While there is absolutely no requirement that sites feature this link, it may be used to show support for Drupal.') . '
';
}
break;
diff --git modules/system/system.test modules/system/system.test
index 05dba78..296ecde 100644
--- modules/system/system.test
+++ modules/system/system.test
@@ -901,7 +901,7 @@ class SystemBlockTestCase extends DrupalWebTestCase {
*/
function testPoweredByBlock() {
// Set block title and some settings to confirm that the interface is availble.
- $this->drupalPost('admin/structure/block/configure/system/powered-by', array('title' => $this->randomName(8), 'color' => 'powered-black', 'size' => '135x42'), t('Save block'));
+ $this->drupalPost('admin/structure/block/configure/' . block_entity_id('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.
@@ -925,7 +925,7 @@ class SystemBlockTestCase extends DrupalWebTestCase {
$edit = array();
$edit['system_powered-by[region]'] = 'footer';
$this->drupalPost('admin/structure/block', $edit, t('Save blocks'));
- $this->drupalPost('admin/structure/block/configure/system/powered-by', array('title' => '', 'color' => 'powered-blue', 'size' => '80x15'), t('Save block'));
+ $this->drupalPost('admin/structure/block/configure/' . block_entity_id('system', 'powered-by'), array('title' => '', 'color' => 'powered-blue', 'size' => '80x15'), t('Save block'));
}
}
diff --git profiles/default/default.install profiles/default/default.install
index 7a02464..6ab7392 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 4889795..5cd2578 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();
// Enable default permissions for system roles.
user_role_set_permissions(DRUPAL_ANONYMOUS_RID, array('access content'));