X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=mkdru.module;h=d988da74edad96ee4c7f774c8d6551be001ff14a;hb=3a8afed1034f596f553f0caafbf54c1588f97ac3;hp=24e36c29aa92567485482a1a033b1518988fa673;hpb=2d59c2185252e78c28eee2f778e5893e5fc78c57;p=mkdru-moved-to-drupal.org.git diff --git a/mkdru.module b/mkdru.module index 24e36c2..d988da7 100644 --- a/mkdru.module +++ b/mkdru.module @@ -71,6 +71,31 @@ function mkdru_access($op, $node, $account) { * Implements hook_menu() */ function mkdru_menu() { + // Can't get tabbed menus to work in D6. The children work and the tabs + // show up there but the top level's url results in it trying to find + // the system module's system.inc in mkdru's directory +// $items['admin/settings/mkdru'] = array( +// 'title' => 'Pazpar2 Metasearch Settings', +// 'description' => 'Settings for mkdru.', +// 'access arguments' => array('administer site configuration'), +// ); +// $items['admin/settings/mkdru/settings'] = array( +// 'title' => 'Settings', +// 'description' => 'Settings for mkdru.', +// 'page callback' => 'drupal_get_form', +// 'page arguments' => array('mkdru_admin_settings'), +// 'type' => MENU_DEFAULT_LOCAL_TASK, +// 'file' => 'mkdru.admin.inc', +// 'weight' => 0, +// ); +// $items['admin/settings/mkdru/ding'] = array( +// 'title' => 'Ding Integration', +// 'description' => 'Search settings for mkdru instance integrated into Ding.', +// 'page callback' => 'drupal_get_form', +// 'page arguments' => array('mkdru_ding_settings'), +// 'type' => MENU_LOCAL_TASK, +// 'weight' => 1, +// ); $items['admin/settings/mkdru'] = array( 'title' => 'Pazpar2 Metasearch Settings', 'description' => 'Settings for mkdru.', @@ -88,6 +113,11 @@ function mkdru_menu() { 'access arguments' => array('administer site configuration'), 'type' => MENU_NORMAL_ITEM, ); + $items['ahah-mkdru-facet'] = array( + 'page callback' => 'mkdru_add_facet_callback', + 'access arguments' => array('create metasearch interface'), + 'type' => MENU_CALLBACK, + ); return $items; } @@ -106,7 +136,7 @@ function mkdru_init() { // function mkdru_settings_form($form, &$form_state) { function mkdru_settings_form(&$form_state) { 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']; @@ -115,6 +145,8 @@ function mkdru_settings_form(&$form_state) { $settings = variable_get('mkdru_defaults', NULL); } + $form['#cache'] = TRUE; + $form['settings'] = array( '#tree' => TRUE, ); @@ -163,10 +195,8 @@ function mkdru_settings_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'), @@ -207,31 +237,66 @@ function mkdru_settings_form(&$form_state) { '#maxlength' => 3, ); } -// $form['new_facet'] = array( -// '#type' => 'fieldset', -// '#title' => t('Add new facet...'), -// '#tree' => TRUE, -// '#collapsible' => TRUE, -// '#collapsed' => FALSE -// ); -// $form['new_facet']['canonical'] = array( -// '#type' => 'textfield', -// '#title' => t('Canonical name of new facet'), -// ); -// $form['new_facet']['button'] = array( -// '#type' => 'submit', -// '#value' => t('Add facet'), -// '#description' => t('Configure additional facets based on Pazpar2/SP termlists'), -// '#weight' => 1, -// '#submit' => array('mkdru_add_facet_form'), -// '#ajax' => array( -// 'callback' => 'mkdru_add_facet_callback', -// 'wrapper' => 'mkdru-facets-form-wrapper', -// ), -// ); + $form['new_facet'] = array( + '#type' => 'fieldset', + '#title' => t('Add new facet...'), + '#tree' => TRUE, + '#collapsible' => TRUE, + '#collapsed' => FALSE + ); + $form['new_facet']['canonical'] = array( + '#type' => 'textfield', + '#title' => t('Canonical name of new facet'), + ); + $form['new_facet']['button'] = array( + '#type' => 'submit', + '#value' => t('Add facet'), + '#description' => t('Configure additional facets based on Pazpar2/SP termlists'), + '#submit' => array('mkdru_add_facet_submit'), + '#ahah' => array( + 'path' => 'ahah-mkdru-facet', + 'wrapper' => 'mkdru-facets-form-wrapper', + ), + ); return $form; } +function mkdru_add_facet_submit($form, &$form_state) { + $newfacet = $form_state['values']['new_facet']['canonical']; + $form_state['values']['settings']['facets'][$newfacet] = NULL; + $form_state['rebuild'] = TRUE; + return $form_state['values']; +} + +function mkdru_add_facet_callback() { + // Necessary to work with hook_form + module_load_include('inc', 'node', 'node.pages'); + + // Retrieve form from cache + $form_state = array('storage' => NULL, 'submitted' => FALSE); + $form_build_id = $_POST['form_build_id']; + $form = form_get_cache($form_build_id, $form_state); + + // Run drupal_process_form to call submit handler and update $form_state + $args = $form['#parameters']; + $form_id = array_shift($args); + $form_state['post'] = $form['#post'] = $_POST; + $form['#programmed'] = $form['#redirect'] = FALSE; + drupal_process_form($form_id, $form, $form_state); + + // Regenerate form so we can render the new facet part + $form = drupal_rebuild_form($form_id, $form_state, $args, $form_build_id); + + // Choose subset of form to redraw. + $facet_form = $form['settings']['facets']; + // Prevent duplicate wrappers. + unset($facet_form['#prefix'], $facet_form['#suffix']); + $output = theme('status_messages') . drupal_render($facet_form); + + // Final rendering callback + drupal_json(array('status' => TRUE, 'data' => $output)); +} + // Ding config @@ -263,7 +328,6 @@ function mkdru_form(&$node, &$form_state) { } $form = drupal_retrieve_form('mkdru_settings_form', &$form_state); - $type = node_get_types('type', $node); $form['title'] = array( '#type' => 'textfield',