Eliminate call to node_object_prepare(&$node) function

mustafau - November 29, 2007 - 10:56
Project:FeedAPI
Version:6.x-1.x-dev
Component:Code
Category:task
Priority:normal
Assigned:Unassigned
Status:postponed
Description

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.

#1

alex_b - November 29, 2007 - 14:56

node_object_prepare() calls the nodeapi('prepare') hooks, which are meant for:

"prepare": The node is about to be shown on the add/edit form.

(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

#2

mustafau - December 9, 2007 - 15:37

I guess calling drupal_execute($form_id, $form_values) might do the same thing.

#3

mustafau - January 21, 2008 - 20:16

node_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:

<?php
/**
* Prepare node for save and allow modules to make changes.
*/
?>

#4

Aron Novak - January 24, 2008 - 19:49
Status:active» active (needs more info)

Thanks 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.

#5

mustafau - February 18, 2008 - 15:41

Any progress on this issue?

#6

Aron Novak - February 18, 2008 - 17:45

Well, 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)

#7

mustafau - March 11, 2008 - 00:20

What about calling node_submit() instead of node_object_prepare().

#8

Aron Novak - March 11, 2008 - 09:32

Please 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.

#9

alex_b - March 17, 2008 - 16:48

We 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

#10

mustafau - April 30, 2008 - 17:24
Version:5.x-1.x-dev» 6.x-1.x-dev
Status:active (needs more info)» postponed

#11

mustafau - May 12, 2008 - 14:26

blogapi_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

#12

newmediaist - October 4, 2008 - 23:23

Just out of curiosity - does anyone know if the above change was ever committed?

 
 

Drupal is a registered trademark of Dries Buytaert.