Index: modules/block/block.admin.inc =================================================================== RCS file: /cvs/drupal/drupal/modules/block/block.admin.inc,v retrieving revision 1.36 diff -u -p -r1.36 block.admin.inc --- modules/block/block.admin.inc 26 Apr 2009 16:30:28 -0000 1.36 +++ modules/block/block.admin.inc 4 May 2009 15:22:46 -0000 @@ -242,6 +258,27 @@ function block_admin_configure(&$form_st '#options' => $role_options, '#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. + $node_types = node_get_types('names'); + $default_type_options = array(); + $result = db_query('SELECT type FROM {block_content_type} WHERE module = :module AND delta = :delta', array(':module' => $module, ':delta' => $delta)); + foreach($result as $type) { + $default_type_options[] = $type->type; + } + $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_types, + '#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( @@ -285,6 +322,10 @@ function block_admin_configure_submit($f foreach (array_filter($form_state['values']['roles']) as $rid) { db_query("INSERT INTO {block_role} (rid, module, delta) VALUES (%d, '%s', '%s')", $rid, $form_state['values']['module'], $form_state['values']['delta']); } + db_query("DELETE FROM {block_content_type} WHERE module = '%s' AND delta = '%s'", $form_state['values']['module'], $form_state['values']['delta']); + foreach (array_filter($form_state['values']['types']) as $type) { + db_query("INSERT INTO {block_content_type} (type, module, delta) VALUES ('%s', '%s', '%s')", $type, $form_state['values']['module'], $form_state['values']['delta']); + } 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(); Index: modules/block/block.install =================================================================== RCS file: /cvs/drupal/drupal/modules/block/block.install,v retrieving revision 1.21 diff -u -p -r1.21 block.install --- modules/block/block.install 26 Apr 2009 16:30:28 -0000 1.21 +++ modules/block/block.install 4 May 2009 15:22:46 -0000 @@ -131,6 +131,34 @@ function block_schema() { ), ); + $schema['block_content_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_types}.type.", + ), + ), + 'primary key' => array('module', 'delta', 'type'), + 'indexes' => array( + 'type' => array('type'), + ), + ); + $schema['box'] = array( 'description' => 'Stores contents of custom-made blocks.', 'fields' => array( Index: modules/block/block.module =================================================================== RCS file: /cvs/drupal/drupal/modules/block/block.module,v retrieving revision 1.329 diff -u -p -r1.329 block.module --- modules/block/block.module 26 Apr 2009 16:30:28 -0000 1.329 +++ modules/block/block.module 4 May 2009 15:22:46 -0000 @@ -576,7 +576,10 @@ function _block_load_blocks() { $blocks = array(); $rids = array_keys($user->roles); - $result = db_query(db_rewrite_sql("SELECT DISTINCT b.* FROM {block} b LEFT JOIN {block_role} r ON b.module = r.module AND b.delta = r.delta WHERE b.theme = '%s' AND b.status = 1 AND (r.rid IN (" . db_placeholders($rids) . ") OR r.rid IS NULL) ORDER BY b.region, b.weight, b.module", 'b', 'bid'), array_merge(array($theme_key), $rids)); + $node = menu_get_object(); + + $result = db_query(db_rewrite_sql("SELECT DISTINCT b.* FROM {block} b LEFT JOIN {block_role} r ON b.module = r.module AND b.delta = r.delta LEFT JOIN {block_content_type} c ON b.module = c.module AND b.delta = c.delta WHERE b.theme = '%s' AND b.status = 1 AND (r.rid IN (" . db_placeholders($rids) . ") OR r.rid IS NULL) AND (" . (isset($node) ? "c.type = '%s' OR" : '') . " c.type IS NULL) ORDER BY b.region, b.weight, b.module", 'b', 'bid'), array_merge(array($theme_key), $rids, isset($node) ? array($node->type) : array())); + while ($block = db_fetch_object($result)) { if (!isset($blocks[$block->region])) { $blocks[$block->region] = array();