Closed (won't fix)
Project:
Drupal core
Version:
x.y.z
Component:
node system
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
11 Nov 2006 at 01:22 UTC
Updated:
11 Nov 2006 at 13:34 UTC
If you want your module FAPI #submit callback to mess with a newly created node ID, you can't currently as $form_values['nid'] is NULL. But what if we form_set_value the nid after doing a node_save in node_form_submit?
This patch is a bit of a proof of concept, so I'd like input on the best way to go about it. But with this we don't need to use hook_nodeapi('insert') and this same method could be applied to taxonomy, users, etc. to make a more generic FAPI solution. I feel like it will have some benefits, but feel free to let me know how it could help you (or not)!
My module example (don't forget the .info file to test):
function mymodule_form_alter($form_id, &$form) {
if (isset($form['type']) && $form['type']['#value'] .'_node_form' == $form_id) {
$form['#submit']['mymodule_mess_with_node'] = array();
}
}
function mymodule_mess_with_node($form_id, $form_values) {
// For new nodes, we need the node ID to mess with it. Test this before/after the patch.
var_dump($form_values['nid']);
die();
// $node = node_load($form_values['nid']);
}
(mymodule.info)
name = My module
description = ""
| Comment | File | Size | Author |
|---|---|---|---|
| node.module_48.patch | 892 bytes | RobRoy |
Comments
Comment #1
morbus iffSubscribed.
Comment #2
RobRoy commentedNow, taking a look at taxonomy_form_term_submit(), taxonomy_form_vocabulary_submit(), user_edit_submit(), etc. a more generic FAPI solution might be in order as to not duplicate this similar form_set_value() chunk of code everywhere, but I can't really think of anything besides a new function taking just the key, and value instead of the parent stuff (which looks suspect).
Possible places needing a similar 'primary key ID' update:
That's for starters, pretty much any form that inserts something generating a new ID would want to update the $form_values ID so other callbacks could modify that item.
Comment #3
RobRoy commentedThis could also be a decent performance boost as we could scrap expensive invoke_all calls like this:
node_invoke_nodeapi($node, 'insert/update');
user_module_invoke('submit', $form_values, $account, $category);
module_invoke_all('taxonomy', 'insert', 'vocabulary', $edit);
and just use form_alter and the FAPI callback to get what we want (might as well since it is already being used). I guess that wouldn't be feasible until 6.0, since it would be a pretty major API change. I may very well be talking out my ass, but just want to get all my thoughts down.
Comment #4
chx commentedI am not too inclined to deal with this. Moshe's nodeapi cleanup patch includes this and more and that's the proper solution. There is no real bug, no real brokenosity here which would mandate a less complete solution.
If there is , then please reopen.
Comment #5
moshe weitzman commentedchx refers to http://drupal.org/node/68418 which perhaps went too far. anyway, i suggest continuing this effrot there.