I was in the need to override the value from the node being pulled in. Attached is a patch.

Here is the how it works :)

for normal fields (title, body)
[node:xxx override=$field:$value;]

This modifies the node object $node->$field = $value

for cck fields:
[node:xxx override=cck:$field:$value:$key:$index; ]

$node->$field[$index][$key] = $value;

The $key and $index are optional. If they are blank:
$node->$field[0]['value'] = $value;

This is run before any html is rendered. It also moves those items from the $params array.

Enjoy! Neil

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

AlexisWilke’s picture

I will add that, but I will also add a flag in the settings so people can turn ON the feature (i.e. by default it would be off). That way, people won't be able to override variables (possibly important for some people!)

Thank you.
Alexis

indytechcook’s picture

Great. I forgot to mention that you can have multiple instances of the override paramater. Great work the module!

AlexisWilke’s picture

Status: Needs review » Fixed

Okay, I put your patch (with minor changes) to the 6.x-dev version. (available within 12h)

Note that you will have to go to your "Input format" configuration screen to be able to use override. Otherwise, those fields are simply ignored.

Thank you.
Alexis Wilke

indytechcook’s picture

Hello Alexis, Thanks for committing again. I did have a quick question about the statement saying the modified node object will be carried outside of this module. I'm not sure I understand.

The node object is statically cached in the node_load function. It's not a global variable. The variable is only used in the _InsertNode_replacer function (and anything it passes the variable to) and is then destroyed.

Other modules calling node_load will get the statically cached version from the node_load function, not the one we modified.

THis is how I understand it, please correct me if I'm wrong.

Neil

indytechcook’s picture

FileSize
783 bytes

On another node, I found a bug with my original patch. If you put the override parameter anywhere but last, when it unsets the item in the $param array, the "for ($idx = 0; $idx < $max; ++$idx)" loop no longer works. Simple fix. This patch is against the latest from dev.

Sorry!
Neil

indytechcook’s picture

Status: Fixed » Needs review

Updating status to reflect new patch

AlexisWilke’s picture

Neil,

Indeed! Thank you for the fix. I put it outside of the loop though.

And for the node_load(), it will indeed return a clone of the node and we only work on the clone. Thus, no danger of changes being carried around. (It is certainly a lot safer that way!)

Thank you.
Alexis

indytechcook’s picture

Status: Needs review » Fixed

Thanks Alexis, I was going to fix that last patch for outside of the loop (because it break if you have multiple overrides).

Glad you caught that :)

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.