Commit b2c61dbd authored by yched's avatar yched

#152016 (followup) : prevent infinite recursion when using the new 'full node'...

#152016 (followup) : prevent infinite recursion when using the new 'full node' : 'teaser' formatters.
parent 15d77f4a
......@@ -165,15 +165,33 @@ function nodereference_field_formatter_info() {
function nodereference_field_formatter($field, $item, $formatter, $node) {
static $titles = array();
// We store the rendered nids in order to prevent infinite recursion
// when using the 'full node' / 'teaser' formatters.
static $recursion_queue = array();
if (empty($item['nid']) || !is_numeric($item['nid'])) {
return '';
}
if ($formatter == 'full' || $formatter == 'teaser') {
$referenced_node = node_load($item['nid']);
$referenced_node->referencing_node = $node;
$referenced_node->referencing_field = $field;
$titles[$item['nid']] = $referenced_node->title;
// If no 'referencing node' is set, we are starting a new 'reference thread'
if (!isset($node->referencing_node)) {
$recursion_queue = array();
}
$recursion_queue[] = $node->nid;
if (in_array($item['nid'], $recursion_queue)) {
// Prevent infinite recursion caused by reference cycles :
// if the node has already been rendered earlier in this 'thread',
// we fall back to 'default' (node title) formatter.
$formatter = 'default';
}
else {
$referenced_node = node_load($item['nid']);
$referenced_node->referencing_node = $node;
$referenced_node->referencing_field = $field;
$titles[$item['nid']] = $referenced_node->title;
}
}
if (!isset($titles[$item['nid']])) {
......@@ -226,7 +244,7 @@ function nodereference_widget($op, &$node, $field, &$items) {
case 'form':
$form = array();
$options = _nodereference_potential_references($field, true);
$options = _nodereference_potential_references($field, TRUE);
foreach ($options as $key => $value) {
$options[$key] = _nodereference_item($field, $value);
}
......
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