Revision 712d7217
Added by Andreas Kohlbecker over 2 years ago
modules/cdm_dataportal/ext_links/ext_links.admin.inc | ||
---|---|---|
148 | 148 |
'#type' => 'textfield', |
149 | 149 |
'#title' => t('Category'), |
150 | 150 |
'#required' => FALSE, |
151 |
'#default_value' => "", |
|
151 |
'#default_value' => $link_template->category, |
|
152 |
'#autocomplete_path' => 'ext_links/category/autocomplete', |
|
152 | 153 |
'#maxlength' => 255, |
153 | 154 |
); |
154 | 155 |
$form['title'] = array( |
modules/cdm_dataportal/ext_links/ext_links.module | ||
---|---|---|
92 | 92 |
// 'type' => MENU_CALLBACK, |
93 | 93 |
'file' => 'ext_links.admin.inc', |
94 | 94 |
]; |
95 |
$items['ext_links/category/autocomplete'] = [ |
|
96 |
'title' => 'Autocomplete for external link categories', |
|
97 |
'page callback' => 'ext_links_category_autocomplete', |
|
98 |
'access arguments' => ['access administration pages'], |
|
99 |
'type' => MENU_CALLBACK |
|
100 |
]; |
|
95 | 101 |
return $items; |
96 | 102 |
} |
97 | 103 |
|
... | ... | |
259 | 265 |
return (bool) db_query_range('SELECT 1 FROM {ext_links} WHERE name = :name', 0, 1, array(':name' => $ext_link_name))->fetchField(); |
260 | 266 |
} |
261 | 267 |
|
268 |
/** |
|
269 |
* Autocomplete function called via the menu hook ext_links/category/autocomplete |
|
270 |
* |
|
271 |
* @param $query_string |
|
272 |
* the string to search for |
|
273 |
*/ |
|
274 |
function ext_links_category_autocomplete($query_string){ |
|
275 |
$matches = array(); |
|
276 |
$sql = 'SELECT * FROM {ext_links} WHERE category LIKE :category'; |
|
277 |
$args = [':category' => '%' . db_like($query_string) . '%']; |
|
278 |
$result = db_query($sql, $args); |
|
279 |
foreach ($result as $row) { |
|
280 |
$matches[$row->category] = check_plain($row->category); |
|
281 |
} |
|
282 |
// Return the result to the form in json |
|
283 |
drupal_json_output($matches); |
|
284 |
} |
|
285 |
|
|
262 | 286 |
|
263 | 287 |
/** |
264 | 288 |
* Returns the genus and the first epithet from the object taxon. |
Also available in: Unified diff
ref #9764 autocomplete for category field