Creating multiple nodes

txcrew - September 30, 2008 - 04:14
Project:Node factory
Version:5.x-1.x-dev
Component:Documentation
Category:support request
Priority:normal
Assigned:Unassigned
Status:active
Description

Greetings,

I'd like to use this module in my project management app to allow for users to create multiple issues from a single 'submit issue' page.

Basically there would be a multi value cck text field.

Can this module create multiple nodes from a multiple value CCK field?

#1

txcrew - September 30, 2008 - 04:16
Version:6.x-1.x-dev» 5.x-1.x-dev

Sorry didn't mean to set to 6.x

#2

txcrew - September 30, 2008 - 04:26

I think I've found the answer in this thread http://drupal.org/node/275754#comment-966591:

<?php
multiselect nodereference population

$nids
= array();
foreach (
$whatev as $nid) {
 
$nids[$nid] = $nid;
 
$field_noderef_multi['nids'] = $nids;

 
$node = new StdClass();
 
$node->type = $newtype;
 
$node->uid = $uid;
 
$node->name = $name;
 
$node->title = $title;
 
$node->status = 1;
 
$node->field_noderef_multi = $field_noderef_multi;

 
node_submit($node);
 
node_save($node);
}
?>

I assume this code is the same for text fields?

#3

clemens.tolboom - September 30, 2008 - 07:50

node_factory has a single value node_factory_set_value('fieldname', 'value'); and a cck multiple values node_factory_set_cck_value( 'fieldname', cck_array_struct); interface. The latter is unfortunately a little clumsy.

So yes you can use all supported widgets node_factory provides.

I hope to provide a node_factory_add_value to support multiple values.

#4

txcrew - September 30, 2008 - 16:27

Sorry, so does that mean the above code will work (please forgive that I'm not by any means a programmer)?

I also just want to be clear that we are not talking about populating one field with multiple values. I'm trying to input multiple values into a single field on one node and then have node factory create multiple nodes from each field in the multiple values.

That being said, what might the syntax be for doing so? Something like:

foreach ($field_mycckfield as $item) {

$edit= node_factory_create_node( 'child');

node_factory_set_value( $edit, 'title', "child [node:title]");
node_factory_set_value( $edit, 'body', $item;

node_factory_save_node( $edit);
}

#5

clemens.tolboom - October 2, 2008 - 10:42

I guess you are using workflow_ng for getting things started?

If you inspect this $field_mycckfield you will not it is an array of array like structure. Install the devel module to look for yourself. So it depends on what's in the field structure what the code would be. See also last paragraphs of http://drupal.org/project/node_factory.

If you need help you can hire me through http://drupal.org/user/125814/contact

 
 

Drupal is a registered trademark of Dries Buytaert.