'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;
}
// 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'];
$settings = variable_get('mkdru_defaults', NULL);
}
+ $form['#cache'] = TRUE;
+
$form['settings'] = array(
'#tree' => TRUE,
);
'#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'),
'#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'];
+ $newfacet = 'PFUI';
+ $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
}
$form = drupal_retrieve_form('mkdru_settings_form', &$form_state);
-
$type = node_get_types('type', $node);
$form['title'] = array(
'#type' => 'textfield',