I created a small custom module to help users while creating a specific content type. Basically the module just adds the autocomplete feature to the title field to show possible duplicate nodes to the user while filling out the form for "on-the-fly" feedback.
The problem is that the autocomplete only works for users with the permission 'Administer nodes'. Is this normal or am I doing something wrong? If it is normal, is there another way to achieve these results without handing out that permission?
Custom module:
<?php
/**
* Implementation of hook_menu()
*/
function duplicates_menu() {
$items = array();
$items['duplicates/check'] = array(
'title' => 'Check for duplicates',
'page callback' => 'duplicates_check',
'access callback' => TRUE,
'type' => MENU_CALLBACK,
);
return $items;
}
/**
* Implementation of hook_form_alter()
*/
function duplicates_form_alter(&$form, $form_state, $form_id) {
if ($form_id == 'company_node_form') {
$form['title']['#autocomplete_path'] = 'duplicates/check';
}
}
/**
* Check for duplicates
*/
function duplicates_check($check) {
$duplicates = array();
if ($check) {
$results = db_query('SELECT title FROM {node} WHERE type = "company" AND LOWER(title) LIKE LOWER("%%%s%%")', $check);
while ($dupes = db_fetch_object($results)) {
$duplicates[$dupes->title] = check_plain($dupes->title);
}
}
print drupal_json($duplicates);
}