+function mkdru_init() {
+ // Applies our module specific CSS to all pages. This works best because
+ // all CSS is aggregated and cached so we reduce the number of HTTP
+ // requests and the size is negligible.
+ drupal_add_css(drupal_get_path('module', 'mkdru') .'/mkdru.css');
+}
+
+
+
+// Config form common to node and settings
+function mkdru_settings_form($form, &$form_state) {
+ if (isset($form_state['values']['settings'])) {
+ $settings = $form_state['values']['settings'];
+ }
+ else if (isset($form_state['build_info']['args']['settings'])) {
+ $settings = $form_state['build_info']['args']['settings'];
+ }
+ else {
+ $settings = variable_get('mkdru_defaults');
+ }
+
+ $form['settings'] = array(
+ '#tree' => TRUE,
+ );
+
+ $form['settings']['pz2_path'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Pazpar2/Service Proxy path'),
+ '#description' => t('Path that takes Pazpar2 commands via HTTP'),
+ '#required' => TRUE,
+ '#default_value' => $settings['pz2_path'],
+ );
+ $form['settings']['use_sessions'] = array(
+ '#type' => 'checkbox',
+ '#title' => t('Session handling'),
+ '#description' => t('Disable for use with Service Proxy'),
+ '#default_value' => $settings['use_sessions'],
+ );
+
+ $form['settings']['sp'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('Service Proxy specific settings'),
+ '#collapsible' => TRUE,
+ '#collapsed' => TRUE
+ );
+ $form['settings']['sp']['user'] = array(
+ '#type' => 'password',
+ '#title' => t('Service Proxy username'),
+ '#description' => t('Service Proxy username'),
+ '#required' => FALSE,
+ '#default_value' => $settings['sp']['user'],
+ );
+ $form['settings']['sp']['pass'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Service Proxy password'),
+ '#description' => t('Service Proxy password'),
+ '#required' => FALSE,
+ '#default_value' => $settings['sp']['pass'],
+ );
+
+ $form['settings']['facets'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('Facet settings'),
+ // Set up the wrapper so that AJAX will be able to replace the fieldset.
+ '#prefix' => '<div id="mkdru-facets-form-wrapper">',
+ '#suffix' => '</div>',
+ '#collapsible' => TRUE,
+ '#collapsed' => FALSE
+ );
+
+ foreach (array_keys($settings['facets']) as $facet) {
+ $form['settings']['facets'][$facet] = array(
+ '#type' => 'fieldset',
+ '#title' => $facet . ' ' . t('facet'),
+ '#collapsible' => TRUE,
+ '#collapsed' => FALSE
+ );
+ $form['settings']['facets'][$facet]['displayName'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Facet name to display in UI'),
+ '#required' => TRUE,
+ '#default_value' => $settings['facets'][$facet]['displayName'],
+ );
+ $form['settings']['facets'][$facet]['pz2Name'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Name of termlist in Pazpar2'),
+ '#required' => TRUE,
+ '#default_value' => $settings['facets'][$facet]['pz2Name'],
+ );
+ $form['settings']['facets'][$facet]['limiter'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Query limiter string'),
+ '#default_value' => $settings['facets'][$facet]['limiter'],
+ '#size' => 5,
+ );
+ $form['settings']['facets'][$facet]['multiLimit'] = array(
+ '#type' => 'checkbox',
+ '#title' => t('Allow multiple limits?'),
+ '#default_value' => $settings['facets'][$facet]['multiLimit'],
+ );
+ $form['settings']['facets'][$facet]['max'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Number of terms to display'),
+ '#required' => TRUE,
+ '#default_value' => $settings['facets'][$facet]['max'],
+ '#size' => 3,
+ '#maxlength' => 3,
+ );
+ $form['settings']['facets'][$facet]['orderWeight'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Facet weight'),
+ '#default_value' => $settings['facets'][$facet]['orderWeight'],
+ '#size' => 3,
+ '#maxlength' => 3,
+ );
+ $form['settings']['facets'][$facet]['remove'] = array(
+ '#type' => 'submit',
+ '#value' => t('Remove ') . $facet . t(' facet'),
+ '#mkdru facet' => $facet,
+ '#submit' => array('mkdru_remove_facet'),
+ '#ajax' => array(
+ 'callback' => 'mkdru_ajax_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'),
+ '#weight' => 1,
+ '#submit' => array('mkdru_add_facet_form'),
+ '#ajax' => array(
+ 'callback' => 'mkdru_ajax_facet_callback',
+ 'wrapper' => 'mkdru-facets-form-wrapper',
+ ),
+ );
+ return $form;
+}
+
+function mkdru_add_facet_form($form, &$form_state) {
+ // TODO: validation
+ $newfacet = $form_state['values']['new_facet']['canonical'];
+ $form_state['values']['settings']['facets'][$newfacet] = NULL;
+ $form_state['rebuild'] = TRUE;
+}
+
+function mkdru_remove_facet($form, &$form_state) {
+ $delfacet = $form_state['clicked_button']['#mkdru facet'];
+ if ($delfacet)
+ unset($form_state['values']['settings']['facets'][$delfacet]);
+ // Block table is not rebuilt like in D6 so we need to remove blocks explicitly
+ // This is a bit preemptive but the block still reappears in block_list if you
+ // decide not to save the facet deletion.
+ db_delete('block')->condition(db_and()
+ ->condition('module', 'mkdru')
+ ->condition('delta', 'mkdru_facet_' . $delfacet . '_' . $form_state['values']['nid'])
+ )->execute();
+ $form_state['rebuild'] = TRUE;
+}
+
+function mkdru_ajax_facet_callback($form, &$form_state) {
+ return $form['settings']['facets'];
+}
+
+
+
+// Ding config
+function mkdru_ding_settings($form, &$form_state) {
+ $form_state['build_info']['args']['settings'] = variable_get('mkdru_ding', NULL);
+ $form = drupal_retrieve_form('mkdru_settings_form', $form_state);
+ $form['settings']['#title'] = t('Search settings for DING integration');
+ $form['submit'] = array(
+ '#type' => 'submit',
+ '#value' => 'Save configuration',
+ );
+ return $form;
+}
+
+function mkdru_ding_settings_submit($form, &$form_state) {
+ variable_set('mkdru_ding', $form_state['values']['settings']);
+ drupal_set_message(t('The configuration options have been saved.'));
+}
+