? admin_settings.patch
? admin_settings_1.patch
Index: exportables.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/exportables/exportables.module,v
retrieving revision 1.7
diff -u -p -r1.7 exportables.module
--- exportables.module	9 Oct 2009 21:59:42 -0000	1.7
+++ exportables.module	9 Oct 2009 22:03:35 -0000
@@ -4,12 +4,131 @@
 /**
  * Implementation of hook_init().
  * 
- * @TODO - find a better place to sync stuff. On a large site this could become
- * unbearably slow.
  * @return void
  */
 function exportables_init() {
-  exportables_sync();
+  if (variable_get('exportables_sync_on_init', 0)) {
+    exportables_sync();
+  }
+}
+
+/**
+ * Implementation of hook_menu().
+ */
+function exportables_menu() {
+  $items = array();
+  $items['admin/build/exportables'] = array(
+    'title' => 'Exportables',
+    'description' => 'Administer exportables.',
+    'access arguments' => array('administer site configuration'),
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('exportables_admin_general_form'),
+    'type' => MENU_NORMAL_ITEM,
+  );
+  $items['admin/build/exportables/general'] = array(
+    'title' => 'General settings',
+    'description' => 'General configuration settings for exportables.',
+    'access arguments' => array('administer site configuration'),
+    'type' => MENU_DEFAULT_LOCAL_TASK,
+  );
+  $items['admin/build/exportables/sync'] = array(
+    'title' => 'Synchronize',
+    'description' => 'Synchronize default items provided by the exportables module hooks.',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('exportables_admin_sync_form'),
+    'access arguments' => array('administer site configuration'),
+    'type' => MENU_LOCAL_TASK,
+  );
+  return $items;
+}
+
+/**
+ * Administration form for basic exportables settings.
+ *
+ * @param array $form_state
+ * @return array FormAPI array describing the form
+ */
+function exportables_admin_general_form($form_state) {
+  $form = array();
+
+  $form['exportables_sync_on_init'] = array(
+    '#type' => 'checkbox',
+    '#title' => t('Sync on init'),
+    '#description' => t('If checked, all exportables defaults will be synchronized with the database on every non-cached page load.  This can cause significant performance problems on large sites.'),
+    '#default_value' => variable_get('exportables_sync_on_init', 0),
+  );
+
+  return system_settings_form($form);
+}
+
+/**
+ * Administration form for synchronizing exportables defaults.
+ *
+ * @param array $form_state
+ * @return array FormAPI array describing the form
+ */
+function exportables_admin_sync_form($form_state) {
+  $form = array();
+
+  $type_info = exportables_type_info();
+  $types = array();
+  foreach ($type_info as $type => $values) {
+    $types[$type] = $type;
+  }
+
+  $form['types'] = array(
+    '#type' => 'checkboxes',
+    '#title' => t('Types'),
+    '#description' => t('Select which type(s) of exportables defaults you would like to sync.  If you do not check anything here, all types while be synchronized on submit.'),
+    '#options' => $types,
+  );
+
+  $form['submit'] = array(
+    '#type' => 'submit',
+    '#title' => t('Resync'),
+    '#value' => t('Resync'),
+  );
+
+  $form['#validate'][] = 'exportables_admin_sync_form_validate';
+  $form['#submit'][] = 'exportables_admin_sync_form_submit';
+
+  return $form;
+}
+
+/**
+ * Validate function for exportables_admin_sync_form().
+ */
+function exportables_admin_sync_form_validate($form, $form_state) {
+  if (array_key_exists('values', $form_state) && array_key_exists('types', $form_state['values'])) {
+    $type_info = exportables_type_info();
+    foreach ($form_state['values']['types'] as $type => $value) {
+      if (!$value) {
+        continue;
+      }
+      if (!array_key_exists($type, $type_info)) {
+        form_set_error('types', t('The requested type !type is not valid.', array('!type' => $type)));
+      }
+    }
+  }
+}
+
+/**
+ * Submit function for exportables_admin_sync_form().
+ */
+function exportables_admin_sync_form_submit($form, $form_state) {
+  $types = array();
+  foreach ($form_state['values']['types'] as $type => $value) {
+    if (!$value) {
+      continue;
+    }
+    $types[] = $type;
+  }
+  if (count($types) > 0) {
+    exportables_sync($types);
+  } else {
+    // Nothing explicitly checked, so sync everything.
+    exportables_sync();
+  }
 }
 
 /**
@@ -140,7 +259,7 @@ function exportables_var_export($var, $p
 
 /**
  * Sync in-code and database versions.
- * @param string $type
+ * @param string|array $type array of types to sync, or single string type
  * @return void
  */
 function exportables_sync($type = '') {
@@ -151,7 +270,7 @@ function exportables_sync($type = '') {
     $types = array($type);
   }
   else {
-    $types = $type;
+    $types = (array) $type;
   }
   foreach ($types as $type) {
     $info = exportables_type_info($type);
