function notifications_node_title2nid in Notifications 6.4
Same name and namespace in other branches
- 6 notifications.node.inc \notifications_node_title2nid()
- 6.2 notifications.node.inc \notifications_node_title2nid()
- 6.3 notifications.node.inc \notifications_node_title2nid()
- 7 includes/node.inc \notifications_node_title2nid()
Reverse mapping from node title to nid
We also handle autocomplete values (title [nid:x]) and validate the form
1 string reference to 'notifications_node_title2nid'
- notifications_notifications in ./
notifications.module - Implementation of hook_notifications()
File
- includes/
node.inc, line 28 - Notifications node API for use by plug-in modules providing node related features
Code
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;
}