summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2009-07-01 08:04:19 +0000
committerDries Buytaert <dries@buytaert.net>2009-07-01 08:04:19 +0000
commit9ce7b3dcdc2cc964f422594b1cc65440cd7decef (patch)
tree306dbe154e0c12af5edaa431bd7b1b394f821d68
parent96f297021cce5e69e16606233a9175987517feda (diff)
downloadbrdo-9ce7b3dcdc2cc964f422594b1cc65440cd7decef.tar.gz
brdo-9ce7b3dcdc2cc964f422594b1cc65440cd7decef.tar.bz2
- Patch #453254 by Pasqualle, Gábor Hojtsy: re-introduce per-content type visibility to block settings.
-rw-r--r--modules/block/block.admin.inc47
-rw-r--r--modules/block/block.install28
-rw-r--r--modules/block/block.module46
3 files changed, 112 insertions, 9 deletions
diff --git a/modules/block/block.admin.inc b/modules/block/block.admin.inc
index 70f7fa1ec..13fad0c5a 100644
--- a/modules/block/block.admin.inc
+++ b/modules/block/block.admin.inc
@@ -252,6 +252,25 @@ function block_admin_configure(&$form_state, $module = NULL, $delta = 0) {
'#description' => t('Show this block only for the selected role(s). If you select no roles, the block will be visible to all users.'),
);
+ // 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,
+ ))->fetchCol();
+ $form['content_type_vis_settings'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('Content type specific visibility settings'),
+ '#collapsible' => TRUE,
+ '#collapsed' => TRUE,
+ );
+ $form['content_type_vis_settings']['types'] = array(
+ '#type' => 'checkboxes',
+ '#title' => t('Show block for specific content types'),
+ '#default_value' => $default_type_options,
+ '#options' => node_type_get_names(),
+ '#description' => t('Show this block only when on a page displaying a post of the given type(s). If you select no types, there will be no type specific limitation.'),
+ );
+
// Standard block configurations.
$form['user_vis_settings'] = array(
'#type' => 'fieldset',
@@ -303,6 +322,7 @@ function block_admin_configure_submit($form, &$form_state) {
->condition('module', $form_state['values']['module'])
->condition('delta', $form_state['values']['delta'])
->execute();
+
db_delete('block_role')
->condition('module', $form_state['values']['module'])
->condition('delta', $form_state['values']['delta'])
@@ -316,11 +336,25 @@ function block_admin_configure_submit($form, &$form_state) {
));
}
$query->execute();
+
+ db_delete('block_node_type')
+ ->condition('module', $form_state['values']['module'])
+ ->condition('delta', $form_state['values']['delta'])
+ ->execute();
+ $query = db_insert('block_node_type')->fields(array('type', 'module', 'delta'));
+ foreach (array_filter($form_state['values']['types']) as $type) {
+ $query->values(array(
+ 'type' => $type,
+ 'module' => $form_state['values']['module'],
+ 'delta' => $form_state['values']['delta'],
+ ));
+ }
+ $query->execute();
+
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();
$form_state['redirect'] = 'admin/build/block';
- return;
}
}
@@ -380,9 +414,18 @@ function block_add_block_form_submit($form, &$form_state) {
}
$query->execute();
+ $query = db_insert('block_node_type')->fields(array('type', 'module', 'delta'));
+ foreach (array_filter($form_state['values']['types']) as $type) {
+ $query->values(array(
+ 'type' => $type,
+ 'module' => $form_state['values']['module'],
+ 'delta' => $delta,
+ ));
+ }
+ $query->execute();
+
drupal_set_message(t('The block has been created.'));
cache_clear_all();
-
$form_state['redirect'] = 'admin/build/block';
}
diff --git a/modules/block/block.install b/modules/block/block.install
index 7d0c30a0c..c68a60286 100644
--- a/modules/block/block.install
+++ b/modules/block/block.install
@@ -131,6 +131,34 @@ function block_schema() {
),
);
+ $schema['block_node_type'] = array(
+ 'description' => 'Sets up display criteria for blocks based on content types',
+ 'fields' => array(
+ 'module' => array(
+ 'type' => 'varchar',
+ 'length' => 64,
+ 'not null' => TRUE,
+ 'description' => "The block's origin module, from {block}.module.",
+ ),
+ 'delta' => array(
+ 'type' => 'varchar',
+ 'length' => 32,
+ 'not null' => TRUE,
+ 'description' => "The block's unique delta within module, from {block}.delta.",
+ ),
+ 'type' => array(
+ 'type' => 'varchar',
+ 'length' => 32,
+ 'not null' => TRUE,
+ 'description' => "The machine-readable name of this type from {node_type}.type.",
+ ),
+ ),
+ 'primary key' => array('module', 'delta', 'type'),
+ 'indexes' => array(
+ 'type' => array('type'),
+ ),
+ );
+
$schema['box'] = array(
'description' => 'Stores contents of custom-made blocks.',
'fields' => array(
diff --git a/modules/block/block.module b/modules/block/block.module
index 06d428c20..0a0c7c954 100644
--- a/modules/block/block.module
+++ b/modules/block/block.module
@@ -618,8 +618,8 @@ function _block_load_blocks() {
/**
* Implement hook_block_list_alter().
*
- * Check the page, role and user specific visibilty settings. Remove the block
- * if the visibility conditions are not met.
+ * Check the page, user role, content type and user specific visibilty settings.
+ * Remove the block if the visibility conditions are not met.
*/
function block_block_list_alter(&$blocks) {
global $user, $theme_key;
@@ -631,6 +631,13 @@ function block_block_list_alter(&$blocks) {
$block_roles[$record->module][$record->delta][] = $record->rid;
}
+ // Build an array of node types for each block.
+ $block_node_types = array();
+ $result = db_query('SELECT module, delta, type FROM {block_node_type}');
+ foreach ($result as $record) {
+ $block_node_types[$record->module][$record->delta][] = $record->type;
+ }
+
foreach ($blocks as $key => $block) {
if ($block->theme != $theme_key || $block->status != 1) {
// This block was added by a contrib module, leave it in the list.
@@ -640,14 +647,39 @@ function block_block_list_alter(&$blocks) {
// If a block has no roles associated, it is displayed for every role.
// For blocks with roles associated, if none of the user's roles matches
// the settings from this block, remove it from the block list.
- if (!isset($block_roles[$block->module][$block->delta])) {
- // No roles associated.
- }
- elseif (!array_intersect($block_roles[$block->module][$block->delta], array_keys($user->roles))) {
+ if (isset($block_roles[$block->module][$block->delta]) && !array_intersect($block_roles[$block->module][$block->delta], array_keys($user->roles))) {
// No match.
unset($blocks[$key]);
continue;
- }
+ }
+
+ // If a block has no node types associated, it is displayed for every type.
+ // For blocks with node types associated, if the node type does not match
+ // the settings from this block, remove it from the block list.
+ if (isset($block_node_types[$block->module][$block->delta])) {
+ $node = menu_get_object();
+ if (!empty($node)) {
+ // This is a node or node edit page.
+ if (!in_array($node->type, $block_node_types[$block->module][$block->delta])) {
+ // This block should not be displayed for this node type.
+ unset($blocks[$key]);
+ continue;
+ }
+ }
+ elseif (arg(0) == 'node' && arg(1) == 'add' && in_array(arg(2), array_keys(node_type_get_types()))) {
+ // This is a node creation page
+ if (!in_array(arg(2), $block_node_types[$block->module][$block->delta])) {
+ // This block should not be displayed for this node type.
+ unset($blocks[$key]);
+ continue;
+ }
+ }
+ else {
+ // This is not a node page, remove the block.
+ unset($blocks[$key]);
+ continue;
+ }
+ }
// Use the user's block visibility setting, if necessary.
if ($block->custom != 0) {