? 303406-theme-settings.patch Index: domain_theme.admin.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/domain/domain_theme/domain_theme.admin.inc,v retrieving revision 1.2 diff -u -p -r1.2 domain_theme.admin.inc --- domain_theme.admin.inc 25 Mar 2009 17:46:34 -0000 1.2 +++ domain_theme.admin.inc 29 Apr 2009 16:21:08 -0000 @@ -52,14 +52,23 @@ function domain_theme_form_alter(&$form, if ($theme['theme']) { $form['theme_default']['#default_value'] = $theme['theme']; } + else { + $form['theme_default']['#default_value'] = ''; + if (empty($_POST)) { + drupal_set_message(t('No theme has been set for this domain.')); + } + } // Unset options that are not allowed. $available = $form['status']['#options']; $allowed = $form['status']['#default_value']; foreach ($available as $key => $value) { if (!in_array($key, $allowed)) { - // If the theme was disabled, then we have to use the default + // If the theme was disabled, then we have to set a new default if ($key == $theme['theme']) { - $form['theme_default']['#default_value'] = variable_get('theme_default', 'garland'); + $form['theme_default']['#default_value'] = ''; + if (empty($_POST)) { + drupal_set_message(t('The chosen theme is no longer available for this domain.'), 'status', FALSE); + } } unset($form[$key]); unset($form['status']['#options'][$key]); @@ -68,6 +77,12 @@ function domain_theme_form_alter(&$form, else { $form['status']['#disabled'] = TRUE; } + + if($form[$key] && $form[$key]['operations']) { + $form[$key]['operations']= array( + '#value' => l(t('configure'), 'admin/build/domain/theme/'. $domain['domain_id'] .'/settings/' . $key), + ); + } } // Use our own submit buttons. $unset = array('buttons', '#submit'); @@ -76,7 +91,7 @@ function domain_theme_form_alter(&$form, } // Message to users. $form['intro'] = array( - '#value' => t('

Select the default theme for this domain. Theme-specific settings must be configured at the system theme settings page.

', array('!url' => url('admin/build/themes'))), + '#value' => t('

Select the default theme for this domain.

'), ); // Which domain are we editing? $form['domain_id'] = array( @@ -90,6 +105,29 @@ function domain_theme_form_alter(&$form, '#value' => t('Set domain theme'), ); } + + if ($form_id == 'system_theme_settings') { + $domain_id = arg(4); + $theme = arg(6); + $themes = list_themes(); + + $domain = domain_load($domain_id); + if ($domain == -1 || !array_key_exists($theme, $themes)) { + return drupal_access_denied(); + } + drupal_set_title(t('!site : %theme settings', array('!site' => $domain['sitename'], '%theme' => $themes[$theme]->info['name']))); + // Which domain are we editing? + $form['domain_id'] = array( + '#type' => 'value', + '#value' => $domain['domain_id'], + ); + $form['theme'] = array( + '#type' => 'value', + '#value' => $theme, + ); + $form['#submit'] = array(); + $form['#submit'][] = 'domain_theme_settings_submit'; + } } /** @@ -97,17 +135,18 @@ function domain_theme_form_alter(&$form, */ function domain_theme_submit($form, &$form_state) { $theme = $form_state['values']['theme_default']; - $id = $form_state['values']['domain_id']; + $domain_id = $form_state['values']['domain_id']; $settings = NULL; // This is a placeholder for advanced functions. - $check = domain_theme_lookup($id); + db_query("UPDATE {domain_theme} SET status = 0 WHERE domain_id = %d", $domain_id); + $check = domain_theme_lookup($domain_id, $theme); if ($check == -1) { - db_query("INSERT INTO {domain_theme} (domain_id, theme, settings) VALUES (%d, '%s', %b)", $id, $theme, $settings); + db_query("INSERT INTO {domain_theme} (domain_id, theme, settings, status) VALUES (%d, '%s', %b, 1)", $domain_id, $theme, $settings); } else { - db_query("UPDATE {domain_theme} SET theme = '%s', settings = %b WHERE domain_id = %d", $theme, $settings, $id); + db_query("UPDATE {domain_theme} SET status = 1 WHERE domain_id = %d AND theme = '%s'", $domain_id, $theme); } // Return to the correct page. - $form_state['redirect'] = 'admin/build/domain/theme/'. $id; + $form_state['redirect'] = 'admin/build/domain/theme/'. $domain_id; } /** @@ -165,3 +204,58 @@ function theme_domain_theme_reset($domai } return $output; } + +/** + * The domain theme page callback router. + * + * @param $domain + * The $domain object created by domain_lookup(). + */ +function domain_theme_settings($domain, $theme) { + // Load the system form file. + include_once(drupal_get_path('module', 'system') . '/system.admin.inc'); + + $data = db_fetch_array(db_query("SELECT theme, settings FROM {domain_theme} WHERE domain_id = %d AND theme = '%s'", $domain['domain_id'], $theme)); + + // If there are settings, we have to load ours. + if (!empty($data)) { + $settings = unserialize($data['settings']); + if (empty($settings)) { + $settings = array(); + } + global $conf; + $conf['theme_'. $theme .'_settings'] = $settings; + return drupal_get_form('system_theme_settings', $data['theme']); + } + else { + return drupal_get_form('system_theme_settings'); + } +} + +/** + * Process domain_theme_settings form submissions. + */ +function domain_theme_settings_submit($form, &$form_state) { + $values = $form_state['values']; + $key = $values['var']; + $domain_id = $values['domain_id']; + $theme = $values['theme']; + // If no record exists, we behave differently. + $check = db_result(db_query("SELECT COUNT(*) FROM {domain_theme} WHERE domain_id = %d AND theme = '%s'", $domain_id, $theme)); + if ($values['op'] == $values['reset'] && $check > 0) { + db_query("UPDATE {domain_theme} SET settings = NULL WHERE domain_id = %d AND theme = '%s'", $domain_id, $theme); + drupal_set_message(t('The configuration options have been reset to their default values.')); + } + else { + // Exclude unnecessary elements before saving. + unset($values['var'], $values['submit'], $values['reset'], $values['form_id'], $values['op'], $values['form_build_id'], $values['form_token'], $values['domain_id']); + $settings = serialize($values); + if ($check > 0) { + db_query("UPDATE {domain_theme} SET settings = %b WHERE domain_id = %d AND theme = '%s'", $settings, $domain_id, $theme); + } + else { + db_query("INSERT INTO {domain_theme} (domain_id, theme, settings, status) VALUES (%d, '%s', %b, 0)", $domain_id, $theme, $settings); + } + drupal_set_message(t('The configuration options have been saved.')); + } +} Index: domain_theme.install =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/domain/domain_theme/domain_theme.install,v retrieving revision 1.4 diff -u -p -r1.4 domain_theme.install --- domain_theme.install 30 Mar 2008 17:51:47 -0000 1.4 +++ domain_theme.install 29 Apr 2009 16:21:08 -0000 @@ -21,8 +21,9 @@ function domain_theme_schema() { 'fields' => array( 'domain_id' => array('type' => 'int', 'not null' => TRUE, 'default' => 0), 'theme' => array('type' => 'varchar', 'length' => '255', 'not null' => TRUE, 'default' => ''), - 'settings' => array('type' => 'blob', 'not null' => FALSE)), - 'primary key' => array('domain_id'), + 'settings' => array('type' => 'blob', 'not null' => FALSE), + 'status' => array('type' => 'int', 'size' => 'tiny', 'not null' => TRUE, 'default' => 0)), + 'primary key' => array('domain_id', 'theme'), ); return $schema; } @@ -34,3 +35,15 @@ function domain_theme_uninstall() { drupal_uninstall_schema('domain_theme'); variable_del('domain_theme_weight'); } + +/** + * Update the table structure + */ +function domain_theme_update_6200() { + $ret = array(); + db_drop_primary_key(&$ret, 'domain_theme'); + db_add_primary_key(&$ret, 'domain_theme', array('domain_id', 'theme')); + db_add_field(&$ret, 'domain_theme', 'status', array('type' => 'int', 'size' => 'tiny', 'not null' => TRUE, 'default' => 0)); + $ret[] = update_sql("UPDATE {domain_theme} SET status = 1"); + return $ret; +} Index: domain_theme.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/domain/domain_theme/domain_theme.module,v retrieving revision 1.13 diff -u -p -r1.13 domain_theme.module --- domain_theme.module 25 Mar 2009 17:46:34 -0000 1.13 +++ domain_theme.module 29 Apr 2009 16:21:09 -0000 @@ -21,15 +21,20 @@ */ function domain_theme_init() { // Assign the theme selected, based on the active domain. - global $_domain, $custom_theme; - // If the theme has already been set (such as an admin theme), ignore. - if (!empty($custom_theme)) { - return; + global $_domain, $custom_theme, $conf; + // If the theme has already been set (such as an admin theme), only load settings. + if (empty($custom_theme)) { + $theme = domain_theme_lookup($_domain['domain_id']); + } + else { + $theme = domain_theme_lookup($_domain['domain_id'], $custom_theme); } - $theme = domain_theme_lookup($_domain['domain_id']); // The above returns -1 on failure. if ($theme != -1) { - $custom_theme = $theme['theme']; + if (!is_null($theme['settings'])) { + $settings = unserialize($theme['settings']); + $conf['theme_' . $custom_theme . '_settings'] = $settings; + } } } @@ -55,6 +60,14 @@ function domain_theme_menu() { 'page arguments' => array(4), 'file' => 'domain_theme.admin.inc', ); + $items['admin/build/domain/theme/%domain/settings'] = array( + 'title' => 'Configure domain theme settings', + 'type' => MENU_CALLBACK, + 'access arguments' => array('administer domains'), + 'page callback' => 'domain_theme_settings', + 'page arguments' => array(4), + 'file' => 'domain_theme.admin.inc', + ); return $items; } @@ -74,21 +87,22 @@ function domain_theme_theme() { * Get domain theme information * * @param $domain_id - * The domain_id taken from {domain}. Optional. + * The domain_id taken from {domain}. * @param $theme * The string representation of a {domain_theme} entry. Optional. - * @param $clear + * If this value is NULL, the default theme for this domain will be returned. + * @param $reset * A boolean flag to clear the static variable if necessary. Not used. Here for consistency. * @return * An array containing the requested row from the {domain_theme} table. * Returns -1 on failure. */ -function domain_theme_lookup($domain_id = NULL, $theme = NULL, $clear = FALSE) { - if (!is_null($domain_id)) { - $return = db_fetch_array(db_query("SELECT domain_id, theme, settings FROM {domain_theme} WHERE domain_id = %d", $domain_id)); +function domain_theme_lookup($domain_id, $theme = NULL, $reset = FALSE) { + if (!is_null($theme)) { + $return = db_fetch_array(db_query("SELECT domain_id, theme, settings, status FROM {domain_theme} WHERE domain_id = %d AND theme= '%s'", $domain_id, $theme)); } - else if (!is_null($theme)) { - $return = db_fetch_array(db_query("SELECT domain_id, theme, settings FROM {domain_theme} WHERE theme= '%s'", $theme)); + else { + $return = db_fetch_array(db_query("SELECT domain_id, theme, settings, status FROM {domain_theme} WHERE domain_id = %d AND status = 1", $domain_id)); } if (empty($return)) { $return = -1;