Node factory

DO NOT USE D6 version ... it's completely untested by me due to time/money constraint ... unless you know what you are doing

API change as of beta-1 of node_factory.module

Ever wanted to create nodes on the fly? This module provides functionality to do this.

With this module you can write code like this to produce a node.

<?php
// my_nodetype must be an existing nodetype
$edit = node_factory_create_node( 'my_nodetype');

node_factory_set_value( $edit, 'title', 'my value');
node_factory_set_value( $edit, 'field_node_ref', 123);
node_factory_set_value( $edit 'uid', 321);
node_factory_save_node( $edit);
?>

Setting taxonomy? Then know the term IDs!

<?php
$edit
['taxonomy'][] = 9; // tid
?>

or know the category ID when free tagging is allowed

<?php
$edit
['taxonomy']['tags'][$vid]= 'a,b,c';
?>

node_factory knows a few CCK fields:

  • node_ref (select)
  • select box (text, int)
  • radio (text, int)
  • checkbox (text, int)

Setting other cck fields?

<?php
node_factory_set_cck_value
( $edit, 'field_node_ref_auto_single', array( array( 'nid' => 47)));
node_factory_set_cck_value( $edit, 'field_node_ref_select_single', array( 'nids' => 47));
node_factory_set_cck_value( $edit, 'field_radio', array( 'key' => 'A'));
node_factory_set_cck_value( $edit, 'field_checkbox', array( 'keys' => array( 'A' => 'A', 'B' => 'B')));
?>

Doing commandline insert? Only in 5.x-1.x-dev

drush nf create json 'json-string'

Do it yourself?

  1. Install the devel module
  2. Look on the Dev load page when viewing the node
  3. Now you see all field names.

Want to debug/help?

You can test yourself with http://drupal.org/project/prepopulate for finding out what parameter you need to fill in a form value. That structure can then be used with node_factory_set_cck_value.

  • Install devel.module
  • Uncomment the function node_factory_nodeapi in node_factory.module
  • Create a specific on field cck node
  • Add a new node by hand
  • Then try it by the devel php code block!
  • Submit a feature request with your cck type attached and your code line solution

Thanks.

Releases

Official releasesDateSizeLinksStatus
5.x-1.0-beta22008-May-2111.21 KBRecommended for 5.xThis is currently the recommended release for 5.x.
Development snapshotsDateSizeLinksStatus
6.x-1.x-dev2008-Aug-158.89 KBDevelopment snapshotDevelopment snapshots are automatically regenerated and their contents can frequently change, so they are not recommended for production use.
5.x-1.x-dev2008-Aug-2913.55 KBDevelopment snapshotDevelopment snapshots are automatically regenerated and their contents can frequently change, so they are not recommended for production use.


 
 

Drupal is a registered trademark of Dries Buytaert.