Insert node to body of another node (filter)

edhel - October 6, 2006 - 08:15

I post text of my quick hack-filter. Syntax:

[node:123] - insert full text (themed by theme('node'))
[node:123 body] - insert node's body
[node:123 teaser] - insert node's teaser
[node:123 link] - insert link to node
[node:123 collapsed] - insert collapsed node's body

Code (put it to file node_filter.module):

<?php
function node_filter_help($section) {
    switch(
$section) {
        case
'admin/modules#description':
            return
t('Filter for including node to body of another node by its ID.');
    }
}

function
_node_filter_replacer($matches) {
   
$node = node_load(array('nid'=>$matches[1]));
    switch (
$matches[2]) {
    case
'body':
        return
$node->body;
    case
'teaser':
        return
$node->teaser;
    case
'link':
        return
l($node->title, "node/$node->nid");
    case
'collapsed':
        return
theme('fieldset', array('#collapsible'=>true, '#collapsed'=>true, '#title'=>$node->title, '#value'=>$node->body));
    default:
        return
theme('node', $node);
    }
}

function
node_filter_filter($op, $delta = 0, $format = -1, $text = '') {
    switch (
$op) {
    case
'list':
        return array(
0 => t('Include/link node by ID'));
    case
'description':
        return
'';
    case
'prepare':
        return
$text;
    case
"process":
       
$text = preg_replace_callback('/\[node:([0-9]+)(?:\s+(body|link|collapsed|teaser))?\]/', '_node_filter_replacer', $text);
        return
$text;
    default:
        return
$text;
    }
}
?>

This is great, thanks. Much

Christefano - February 2, 2007 - 16:50

This is great, thanks. Much better for my needs than the attached_node module.

Drupal 5 Node (filter)

Summit - September 4, 2007 - 20:25

Hi,

Can somebody please port this code to drupal 5.2?

Thanks in advance,
greetings,
Martijn

Just checked in a module

markfoodyburton - January 10, 2008 - 14:05

Just checked in a module that does this as a filter
Its called InsertNode

http://drupal.org/project/InsertNode

Hope it helps

This would be an ideal

gost_gost - May 19, 2008 - 19:16

This would be an ideal module if we could get it to work with 5.7
it appears not to be...

The module requires turning

gost_gost - May 19, 2008 - 23:18

The module requires turning on filter after installation.
See here:
http://drupal.org/node/253243#comment-849898

 
 

Drupal is a registered trademark of Dries Buytaert.