title, "node/$nid") : check_plain($node->title); } else { return t('Not found'); } } /** * Reverse mapping from node title to nid * * We also handle autocomplete values (title [nid:x]) and validate the form */ function notifications_node_title2nid($name, $field = NULL, $types = array()) { if (!empty($name)) { preg_match('/^(?:\s*|(.*) )?\[\s*nid\s*:\s*(\d+)\s*\]$/', $name, $matches); if (!empty($matches)) { // Explicit [nid:n]. list(, $title, $nid) = $matches; if (!empty($title) && ($node = node_load($nid)) && $title != $node->title) { if ($field) { form_set_error($field, t('Node title mismatch. Please check your selection.')); } $nid = NULL; } } else { // No explicit nid. $reference = _notifications_node_references($name, 'equals', $types, 1); if (!empty($reference)) { $nid = key($reference); } elseif ($field) { form_set_error($field, t('Found no valid post with that title: %title', array('%title' => $name))); } } } return !empty($nid) ? $nid : NULL; } /** * Generates 'title [nid:$nid]' for the autocomplete field */ function notifications_node_nid2autocomplete($nid) { if ($node = node_load($nid)) { return check_plain($node->title) . ' [nid:' . $nid .']'; } else { return t('Not found'); } } /** * Menu callback; Retrieve a pipe delimited string of autocomplete suggestions for existing users */ function notifications_node_autocomplete_title($string = '') { $matches = array(); foreach (_notifications_node_references($string) as $id => $row) { // Add a class wrapper for a few required CSS overrides. $matches[$row['title'] ." [nid:$id]"] = '