Index: domain_blocks.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/domain_blocks/domain_blocks.module,v retrieving revision 1.3 diff -u -r1.3 domain_blocks.module --- domain_blocks.module 30 Apr 2009 01:02:35 -0000 1.3 +++ domain_blocks.module 14 Nov 2009 02:02:17 -0000 @@ -135,6 +135,10 @@ $form['#submit'][] = 'domain_blocks_form_submit'; } } + // Add submit handler for block_admin_display_form + if ($form_id == 'block_admin_display_form') { + $form['#submit'][] = 'domain_blocks_admin_display_submit'; + } } /** @@ -161,6 +165,22 @@ } /** + * Grant domain_site permission when blocks are enabled on main blocks + * administration form submission. + */ +function domain_blocks_admin_display_submit($form, &$form_state) { + foreach ($form_state['values'] as $block) { + $block['status'] = $block['region'] != BLOCK_REGION_NONE; + $block['region'] = $block['status'] ? $block['region'] : ''; + // Grant domain_site permission if no specific permissions are set + $domain_realm = _domain_blocks_domain_realm_lookup($block['module'], $block['delta']); + if (empty($domain_realm)) { + domain_blocks_save($block['module'], $block['delta'], array()); + } + } +} + +/** * Implementation of hook_db_rewrite_sql(). */ function domain_blocks_db_rewrite_sql($query, $primary_table, $primary_key, $args) { @@ -188,6 +208,21 @@ return $result; } +/** + * Look up domain grants for a block based on block module and delta + * + * @param string $module + * @param string $delta + * @return array + */ +function _domain_blocks_domain_realm_lookup($module = NULL, $delta = NULL) { + $result = array(); + if (!is_null($module) && !is_null($delta)) { + $result = db_fetch_array(db_query("SELECT realm from {domain_blocks} WHERE module = '%s' AND delta = '%s'", $module, $delta)); + } + return $result; +} + function _domain_blocks_load($module, $delta, $realm = NULL) { $block = array(); if (!empty($realm)) {