No options

  1. <?php
  2. /**
  3.  * Implementation of hook_menu().
  4.  */
  5. function nrc_authormerge_menu($may_cache) {
  6.   $items = array();
  7.   if ($may_cache) {
  8.     $items[] = array(
  9.       'path' => 'author/autocomplete',
  10.       'callback' => 'nrc_authormerge_autocomplete',
  11.       'title' => t('Search matching authors'),
  12.       'access' => user_access('access content'),
  13.       'type' => MENU_CALLBACK,
  14.     );
  15.   }
  16.   return $items;
  17. }
  18.  
  19. /**
  20.  * Implementation of hook_nodeapi().
  21.  * @todo show only on certain criteria (ie body empty etc)
  22.  */
  23. function nrc_authormerge_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
  24.   if ($node->type == 'author' && $op == 'view' && $a4 != false && user_access('administer nodes')) {    
  25.     $form = drupal_get_form('nrc_authormerge_searchbox', $node->nid);
  26.     $node->content['searchbox']['#value'] = $form;
  27.     //dpm($node);
  28.   }
  29. }
  30.  
  31. /**
  32.  * Autocomplete callback, returns authors.
  33.  */
  34. function nrc_authormerge_autocomplete($string = '') {
  35.  
  36.   /*$result = db_query("SELECT n.nid, n.title AS node_title FROM {node} n WHERE n.type = 'author' AND n.title LIKE '%%%s%' ORDER BY n.title", $string);
  37.   while ($row = db_fetch_object($result)) {
  38.     $matches[$row->node_title .' [nid:'. $row->nid .']'] = check_plain($row->node_title);
  39.   }*/
  40.  
  41.   // watchdog here shows that this function is called
  42.   // but still, even this simple array doesn't popup in the autocomplete textfield.
  43.   $matches['blah'] = 'test 1';
  44.   $matches['blah2'] = 'test 2';
  45.  
  46.   drupal_to_js($matches);
  47.   exit();
  48. }
  49.  
  50. /**
  51.  * Search block with autocomplete form
  52.  */
  53. function nrc_authormerge_searchbox($nid) {
  54.   $form['author_search'] = array(
  55.     '#required' => true,
  56.     '#type' => 'textfield',
  57.     '#title' => t('Zoek een auteur'),
  58.     '#autocomplete_path' => 'author/autocomplete'
  59.   );
  60.   $form['thisnid'] = array(
  61.     '#type' => 'hidden',
  62.     '#value' => $nid
  63.   );
  64.   $form['submit'] = array(
  65.     '#type' => 'submit',
  66.         '#value' => t('Merge!')
  67.   );
  68.   return $form;
  69. }