You are here

function notifications_node_title2nid in Notifications 6

Same name and namespace in other branches
  1. 6.4 includes/node.inc \notifications_node_title2nid()
  2. 6.2 notifications.node.inc \notifications_node_title2nid()
  3. 6.3 notifications.node.inc \notifications_node_title2nid()
  4. 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 call to notifications_node_title2nid()
notifications_feed_title2nid in notifications_feed/notifications_feed.module
Subscription field mapping
1 string reference to 'notifications_node_title2nid'
notifications_content_notifications in notifications_content/notifications_content.module
Implementation of hook_notifications()

File

./notifications.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;
}