function node_reference_autocomplete_value in References 7.2
Value callback for a node_reference autocomplete element.
Replace the node nid with a node title.
@codingStandardsIgnoreStart
1 string reference to 'node_reference_autocomplete_value'
- node_reference_field_widget_form in node_reference/
node_reference.module - Implements hook_field_widget_form().
File
- node_reference/
node_reference.module, line 684 - Defines a field type for referencing one node from another.
Code
function node_reference_autocomplete_value($element, $input = FALSE, $form_state) {
// @codingStandardsIgnoreEnd
if ($input === FALSE) {
// We're building the displayed 'default value': expand the raw nid into
// "node title [nid:n]".
$nid = $element['#default_value'];
if (!empty($nid)) {
$q = db_select('node', 'n');
$q
->addField('n', 'title');
$q
->addTag('node_access')
->condition('n.nid', $nid)
->range(0, 1);
$result = $q
->execute();
// @todo If no result (node doesn't exist or no access).
$value = $result
->fetchField();
$value .= ' [nid:' . $nid . ']';
return $value;
}
}
}