Commit 4cadbe09 authored by yched's avatar yched

#126926 - skip node_load in noderef formatter - patch by Crell (slightly modified)

parent a05bdddb
...@@ -141,11 +141,11 @@ function nodereference_field($op, &$node, $field, &$items, $teaser, $page) { ...@@ -141,11 +141,11 @@ function nodereference_field($op, &$node, $field, &$items, $teaser, $page) {
function nodereference_field_formatter_info() { function nodereference_field_formatter_info() {
return array( return array(
'default' => array( 'default' => array(
'label' => 'Default', 'label' => 'Title (link)',
'field types' => array('nodereference'), 'field types' => array('nodereference'),
), ),
'plain' => array( 'plain' => array(
'label' => 'Plain text', 'label' => 'Title (no link)',
'field types' => array('nodereference'), 'field types' => array('nodereference'),
), ),
); );
...@@ -155,20 +155,23 @@ function nodereference_field_formatter_info() { ...@@ -155,20 +155,23 @@ function nodereference_field_formatter_info() {
* Implementation of hook_field_formatter(). * Implementation of hook_field_formatter().
*/ */
function nodereference_field_formatter($field, $item, $formatter, $node) { function nodereference_field_formatter($field, $item, $formatter, $node) {
$text = ''; static $titles = array();
if (!empty($item['nid'])) {
$referenced_node = node_load($item['nid']); if (empty($item['nid'])) {
if ($referenced_node) { return '';
$text = l($referenced_node->title, 'node/'. $referenced_node->nid);
}
} }
if (!isset($titles[$item['nid']])) {
$title = db_result(db_query("SELECT title FROM {node} WHERE nid=%d", $item['nid']));
$titles[$item['nid']] = $title ? $title : '';
}
switch ($formatter) { switch ($formatter) {
case 'plain': case 'plain':
return strip_tags($text); return $titles[$item['nid']];
default: default:
return $text; return l($titles[$item['nid']], 'node/'. $item['nid']);
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment