function i18n_node_autocomplete2nid in Internationalization 6
Same name and namespace in other branches
- 7 i18n_node/i18n_node.pages.inc \i18n_node_autocomplete2nid()
Reverse mapping from node title to nid
We also handle autocomplete values (title [nid:x]) and validate the form
1 call to i18n_node_autocomplete2nid()
- i18n_node_select_translation_validate in ./
i18n.pages.inc - Form validation
File
- ./
i18n.pages.inc, line 184 - User page callbacks for the translation module.
Code
function i18n_node_autocomplete2nid($name, $field = NULL, $type, $language) {
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 = _i18n_node_references($name, 'equals', array(
'type' => $type,
'language' => $language,
), 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;
}