Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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
Comment | File | Size | Author |
---|---|---|---|
#5 | InsertNode-744368-2.patch | 783 bytes | indytechcook |
InsertNode-override.patch | 1.63 KB | indytechcook |
Comments
Comment #1
AlexisWilke CreditAttribution: AlexisWilke commentedI 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
Comment #2
indytechcook CreditAttribution: indytechcook commentedGreat. I forgot to mention that you can have multiple instances of the override paramater. Great work the module!
Comment #3
AlexisWilke CreditAttribution: AlexisWilke commentedOkay, 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
Comment #4
indytechcook CreditAttribution: indytechcook commentedHello 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
Comment #5
indytechcook CreditAttribution: indytechcook commentedOn 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
Comment #6
indytechcook CreditAttribution: indytechcook commentedUpdating status to reflect new patch
Comment #7
AlexisWilke CreditAttribution: AlexisWilke commentedNeil,
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
Comment #8
indytechcook CreditAttribution: indytechcook commentedThanks 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 :)