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.
node_object_prepare(&$node)
function in node.module was moved to node.pages.inc in drupal-6.0-beta3. I think it should not be used outside the node module.
Comments
Comment #1
alex_b CreditAttribution: alex_b commentednode_object_prepare() calls the nodeapi('prepare') hooks, which are meant for:
(http://api.drupal.org/api/function/hook_nodeapi/5)
FeedAPI uses node_object_prepare() to simulate the creation of a node - modules get time to do their presets on the node (e. g. have a look at node_prepare()).
I don't really like the idea that we make other modules believe that we are about to show a node on the add/edit form, either. Whats a best practice for automatic node creation? What would be a good alternative?
Related: http://drupal.org/node/165388#comment-620821
Comment #2
mustafau CreditAttribution: mustafau commentedI guess calling
drupal_execute($form_id, $form_values)
might do the same thing.Comment #3
mustafau CreditAttribution: mustafau commentednode_object_prepare() and node_prepare() functions are meant to simulate the demonstration of a node. I think in order to simulate the creation you should call node_submit().
The comment on node_submit() is:
Comment #4
Aron NovakThanks for warning me, yes, i faced with huge problems when i started to implement "creating node via drupal_execute" task.
The most serious is the following:
I had a line similar to this: drupal_execute($old_node->type. '_node_form', $values, $node);
drupal_execute has NO return value if there is no problem and $node structure remains unaltered. There is only 2 way to get the nid : run a direct SQL query or do node_load() . Both of them are too expensive.
Anyway, I know that this IS a problem, because I faced with an issue, which roots are from here : http://drupal.org/node/195105 . So the core forum module uses form_alter to pass taxonomy-like data. And this data is lost now. That's why I started to implement node creation w/ drupal_execute, but it makes even bigger problems.
Comment #5
mustafau CreditAttribution: mustafau commentedAny progress on this issue?
Comment #6
Aron NovakWell, because of the above problems, i do not plan to solve this for DRUPAL-5, but i have to solve it for FeedAPI for Drupal 6 (it will be available soon) and the solution can be backported (if it's possible)
Comment #7
mustafau CreditAttribution: mustafau commentedWhat about calling node_submit() instead of node_object_prepare().
Comment #8
Aron NovakPlease check out this thread:
http://lists.drupal.org/archives/development/2008-03/msg00063.html
Yes, your suggested change is reasonable, although there is no perfect way to do currently.
node_submit seems to be a really good candidate, but for example there is a permission checking inside it, i had to fill the uid manually, for example.
Soon I'll test the effects of changing node_object_prepare() lines to node_submit.
Comment #9
alex_b CreditAttribution: alex_b commentedWe should try to do #7 - be aware that there are all sorts of ramifications in the module family - off the top of my head there are feedapi_mapper and feedapi_inherit that count on getting a call to 'prepare'. feedapi_node itself creates feed item nodes with calling 'prepare' but not 'submit'.
Alex
Comment #10
mustafau CreditAttribution: mustafau commentedComment #11
mustafau CreditAttribution: mustafau commentedblogapi_blogger_new_post() is a good example of creating nodes programmatically. I think it is the only function that creates node programmatically in Drupal core.
http://api.drupal.org/api/function/blogapi_blogger_new_post
Comment #12
newmediaist CreditAttribution: newmediaist commentedJust out of curiosity - does anyone know if the above change was ever committed?
Comment #13
kentr CreditAttribution: kentr commentedNot in Drupal core, of course, but perhaps an example: Mailhandler creates new nodes via email.