Building $node->body with arrays like FAPI for viewing

Created on 18 July 2006, about 18 years ago
Updated 24 July 2023, about 1 year ago

[Moving mailing list discussion here for posting patches in the future.]

I'm talking about the displaying of nodes using PHPTemplate. Right now hook_nodeapi($op = 'view' or 'links' etc.) has a lot of modules adding to the body like this

$node->body .= $output;

Maybe there is a module_setting to put it on TOP of the body or on the BOTTOM. But most modules just append. When displaying the node, all of that comes into $content in node.tpl.php. So if you want to configure that, you have to redo the whole body yourself. Then, if you install another module that adds to the node body through hook_nodeapi you have to go manually add that to your node.tpl.php for each one.

If we constructed it like FAPI, with weights, etc. We could allow modifications of that right before calling render_body($node) or whatever. So hook_nodeapi('view') could do something like

$body['mymodule']['extra_stuff_added_to_node'] = array(
'#type' => 'markup', // Any other possible values or is it always markup? What about adding quick forms to send to friend etc.?
'#value' => '

Cool stuff added to end of node, but can be removed or rearranged with hook_body_alter();

',
'#weight' => 10, // or could even have variable_get('mymodule_extra_stuff_added_to_node_weight, 10);
);

We could even add comments this way and have much more flexibility to configure when, where, and how items are added to the node body. Also, configuring these options (value, weight) in _settings would be that much easier. Then, with hook_body_alter we can mess with the weights, values, remove just this ONE item without manually reconstructing $content in our node.tpl.php. Also, this could be applied to links I believe.

Patch coming sometime soon...

πŸ“Œ Task
Status

Fixed

Version

5.0 ⚰️

Component
Node systemΒ  β†’

Last updated 1 minute ago

No maintainer
Created by

πŸ‡ΊπŸ‡ΈUnited States RobRoy

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024