New facets show up when editing existing node.
authorJason Skomorowski <jason@indexdata.com>
Thu, 24 Mar 2011 07:56:48 +0000 (07:56 +0000)
committerJason Skomorowski <jason@indexdata.com>
Thu, 24 Mar 2011 07:56:48 +0000 (07:56 +0000)
mkdru.install
mkdru.module

index 9bdf3a5..785443b 100644 (file)
@@ -79,6 +79,7 @@ function mkdru_install() {
 function mkdru_uninstall() {
   // Delete variables
   variable_del('pz2_js_path');
+  variable_del('mkdru_defaults');
   // Clear block visibility
   db_delete('block_node_type')->condition('module', 'mkdru')->execute();
 }
\ No newline at end of file
index f1dcfc6..636eb92 100644 (file)
@@ -164,7 +164,7 @@ function mkdru_settings_form($form, &$form_state) {
   dpm($form_state);
 //   dpm($settings);
   if (isset($form_state['values']['settings'])) {
-    $settings = $form_state['build_info']['args']['settings'];
+    $settings = $form_state['values']['settings'];
   }
   else if (isset($form_state['build_info']['args']['settings'])) {
     $settings = $form_state['build_info']['args']['settings'];
@@ -177,14 +177,6 @@ function mkdru_settings_form($form, &$form_state) {
     '#tree' => TRUE,
   );
 
-  $form['settings']['title'] = array(
-    '#type' => 'textfield',
-    '#title' => t('Search title'),
-    '#required' => FALSE,
-    '#default_value' => $settings['title'],
-    '#weight' => -5
-  );
-
   $form['settings']['pz2_path'] = array(
     '#type' => 'textfield',
     '#title' => t('Pazpar2/Service Proxy path'),
@@ -229,10 +221,8 @@ function mkdru_settings_form($form, &$form_state) {
     '#collapsible' => TRUE,
     '#collapsed' => FALSE
   );
-  if (empty($form_state['facet_names'])) {
-    $form_state['facet_names'] = array('source', 'author', 'subject');
-  }
-  foreach ($form_state['facet_names'] as $facet) {
+
+  foreach (array_keys($settings['facets']) as $facet) {
     $form['settings']['facets'][$facet]  = array(
       '#type' => 'fieldset',
       '#title' => $facet . ' ' . t('facet'),
@@ -273,6 +263,7 @@ function mkdru_settings_form($form, &$form_state) {
       '#maxlength' => 3,
     );
   }
+
   $form['new_facet']  = array(
     '#type' => 'fieldset',
     '#title' => t('Add new facet...'),
@@ -304,19 +295,26 @@ function mkdru_settings_form($form, &$form_state) {
 * Implements hook_form()
 */
 function mkdru_form(&$node, &$form_state) {
-// Can't use the node type's title since
-// merging AJAX forms is currently beyond me.
-//   $type = node_type_get_type($node);
-//   Title would be: check_plain($type->title_label);
   if (isset($node->mkdru->settings)) {
     // Second decode parameter indicates associative array
     $form_state['build_info']['args']['settings'] = json_decode($node->mkdru->settings, TRUE);
   }
-  return drupal_retrieve_form('mkdru_settings_form', $form_state);
+  $form = drupal_retrieve_form('mkdru_settings_form', $form_state);
+  $type = node_type_get_type($node);
+  $form['title'] = array(
+    '#type' => 'textfield',
+    '#title' => check_plain($type->title_label),
+    '#required' => FALSE,
+    '#default_value' => $node->title,
+    '#weight' => -5
+  );
+  return $form;
 }
 
 function mkdru_add_facet_form($form, &$form_state) {
-  $form_state['facet_names'][] = $form_state['values']['new_facet']['canonical'];
+  // TODO: validation
+  $newfacet = $form_state['values']['new_facet']['canonical'];
+  $form_state['values']['settings']['facets'][$newfacet] = NULL;
   $form_state['rebuild'] = TRUE;
 }