Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

adding feature to export and properly revert theme settings custom to…

… the omega theme
  • Loading branch information...
commit fba2a84232316f011274afbd403a5552fae93ee3 1 parent 35f4785
Jake Strawn authored

Showing 1 changed file with 82 additions and 15 deletions. Show diff stats Hide diff stats

  1. +82 15 omega_tools.module
97 omega_tools.module
@@ -37,17 +37,82 @@ function omega_tools_form_alter(&$form, $form_state, $form_id) {
37 37 // we have a specific theme settings page defined, so we are going to render
38 38 // a custom fieldset and submit button/handler that will allow a user to reset
39 39 // the theme settings stored in the system.
40   - $form['omega_tools_reset'] = array(
41   - '#type' => 'fieldset',
42   - '#title' => t('Revert Theme Settings'),
43   - '#collapsible' => TRUE,
44   - '#collapsed' => TRUE,
45   - '#description' => '<p><strong>Use this feature with caution!!!</strong></p><p>Using this feature will allow you to revert your theme settings to anything that is in code, and erase the database stored settings in the <em>system</em> table. This is accomplished by removing the record in the table, and then re-enabling the theme. All settings from the .info file will be used rather than any stored changes in the database.</p>',
46   - '#weight' => -50,
47   - );
48   - $form['omega_tools_reset']['theme_reset'] = array(
49   - '#markup' => l('Revert Theme Settings for '. $theme, 'admin/appearance/settings/'. $theme .'/reset'),
50   - );
  40 +
  41 +
  42 +
  43 +
  44 +
  45 + $themes = list_themes();
  46 + if(isset($themes[$theme]->base_theme) && $themes[$theme]->base_theme == 'omega') {
  47 + $form['omega_tools_reset'] = array(
  48 + '#type' => 'fieldset',
  49 + '#title' => t('Revert Theme Settings'),
  50 + '#collapsible' => TRUE,
  51 + '#collapsed' => TRUE,
  52 + '#description' => '<p><strong>Use this feature with caution!!!</strong></p><p>Using this feature will allow you to revert your theme settings to anything that is in code, and erase the database stored settings in the <em>system</em> table. This is accomplished by removing the record in the table, and then re-enabling the theme. All settings from the .info file will be used rather than any stored changes in the database.</p><p>If you would like to save the theme settings you have now, and put them in code, use the export feature, and paste the settings[] array in your .info file replacing the current values for that array. Then it will be safe to revert without destroying changes made to the theme settings for your subtheme.</p><p>If you have manually edited the settings in the .info file, and are unconcerned with the settings in the database, or the settings in the database are out of date, then it is also safe to revert.</p>',
  53 + '#weight' => 50,
  54 + );
  55 + $form['omega_tools_reset']['theme_reset'] = array(
  56 + '#markup' => l('Revert Theme Settings for '. $theme, 'admin/appearance/settings/'. $theme .'/reset'),
  57 + );
  58 + $form['omega_tools_export'] = array(
  59 + '#type' => 'fieldset',
  60 + '#title' => t('Export Theme Settings'),
  61 + '#collapsible' => TRUE,
  62 + '#collapsed' => TRUE,
  63 + '#description' => '<p>This feature will dump the settings[] array for your .info file, so you may safely paste this data over the appropriate section in your themes .info, and then use the revert feature without actually using your settings <strong>&lt;/theme-export-awesomesause&gt;</strong>.</p>',
  64 + '#weight' => 49,
  65 + );
  66 + // gather theme information
  67 + $overwritten_settings = variable_get('theme_'. $theme .'_settings', FALSE);
  68 +
  69 + if($overwritten_settings) {
  70 +
  71 +
  72 + $form['omega_tools_export']['theme_settings_status'] = array(
  73 + '#markup' => 'Current Theme Settings status: <strong>Overwritten</strong>',
  74 + );
  75 + $s = $overwritten_settings;
  76 + unset(
  77 + $s['toggle_logo'],
  78 + $s['toggle_name'],
  79 + $s['toggle_slogan'],
  80 + $s['toggle_node_user_picture'],
  81 + $s['toggle_comment_user_picture'],
  82 + $s['toggle_comment_user_verification'],
  83 + $s['toggle_favicon'],
  84 + $s['toggle_main_menu'],
  85 + $s['toggle_secondary_menu'],
  86 + $s['default_logo'],
  87 + $s['logo_path'],
  88 + $s['logo_upload'],
  89 + $s['default_favicon'],
  90 + $s['favicon_path'],
  91 + $s['favicon_upload']
  92 + );
  93 + krumo($s);
  94 + $export_vars = '';
  95 + foreach($s AS $key => $val) {
  96 + if (isset($val) && !empty($val)) {
  97 + $export_vars .= "settings[".$key."] = ".$val ."\n";
  98 + }
  99 + else {
  100 + $export_vars .= "settings[".$key."] = ''\n";
  101 + }
  102 + }
  103 + $form['omega_tools_export']['theme_settings_export_code'] = array(
  104 + '#type' => 'textarea',
  105 + '#title' => t('Export Code'),
  106 + '#default_value' => $export_vars,
  107 + '#description' => 'You will want to paste this code in the .info file of your subtheme and overwrite the entire settings[] section to properly export this code.',
  108 + );
  109 + }
  110 + else {
  111 + $form['omega_tools_export']['theme_settings_status'] = array(
  112 + '#markup' => 'Current Theme Settings status: <strong>In Code (.info)</strong>',
  113 + );
  114 + }
  115 + }
51 116 }
52 117 else {
53 118 // we are on the default settings page, so we are going to render the option to enable/disable
@@ -181,13 +246,15 @@ function _omega_tools_theme_reset_submit($form, $form_state) {
181 246 $form_state['redirect'] = '/admin/appearance/settings/'. $theme;
182 247 // remove the stored DB copy of the theme settings that have been modified
183 248 variable_del('theme_'.$theme.'_settings');
184   - // clear the cache in case that will help
185   - cache_clear_all();
  249 + // clear the cache in case that will help
  250 + drupal_flush_all_caches();
186 251 // rebuild the theme information
187 252 system_rebuild_theme_data();
188   - // make a nice message to say it happened, and log to the system
  253 + // clear the cache in case that will help
  254 + drupal_flush_all_caches();
  255 + // report to the log
189 256 watchdog('theme', 'Theme settings for %theme reset to default values.', array('%theme' => $theme));
190   -
  257 + // make a nice message to say it happened, and log to the system
191 258 drupal_set_message('Theme settings for <strong>'. $form_state['values']['theme'] .'</strong> have been reset...');
192 259 // go back to the primary settings page for this theme
193 260 drupal_redirect_form($form_state);

0 comments on commit fba2a84

Please sign in to comment.
Something went wrong with that request. Please try again.