[development] programmatic creation of node
Earnie Boyd
earnie at users.sourceforge.net
Mon Mar 10 12:40:26 UTC 2008
Quoting Ashraf Amayreh <mistknight at gmail.com>:
> Just wanted to point that this is just dummy code so no one thinks it's
> actually anything related to the aggregation module itself. But the new
> release will follow a similar pattern, unless I get feedback on a better way
> to do it :)
>
> On Sat, Mar 8, 2008 at 8:30 PM, Ashraf Amayreh <mistknight at gmail.com> wrote:
>
>> For better or worse, this is the code I use in the aggregation module and
>> it seems to be working flawlessly. This is in the yet to be released release
>> though (drupal 5). If there's a better way I'd be glad to know it.
>>
>> (INSERT)
>> $node = new stdClass();
>> $node->title = "{$XML->name}";
>> $node->body = "{$XML->description}";
>> $node->eid = $eid;
>>
>> node_save($node);
>> module_invoke_all('nodeapi', $node, 'insert', NULL, NULL);
>>
>> --------------
>> (UPDATE)
>> $node = node_load(array('nid' => 5));
>> $node->title = "{$XML->name}";
>> $node->body = "{$XML->description}";
>> $node->eid = $eid;
>>
>> node_save($node);
>> module_invoke_all('nodeapi', $node, 'update', NULL, NULL);
>>
http://api.drupal.org/api/function/node_save already calls the module
hooks for nodeapi via
http://api.drupal.org/api/function/node_invoke_nodeapi before
returning. Therefore your module_invoke_all isn't needed.
Earnie -- http://for-my-kids.com/
-- http://give-me-an-offer.com/
More information about the development
mailing list