Greetings Sunset Bill.

First off, I want to tell you what an awesome module you have created. It works out of the box as advertised. The documentation is clear and concise. I was able to follow it and add the autocreation of two additional content types (a spreadsheet and a news article) when I create my root content type. But right where the documentation leaves off, I have some questions:

• When I create my root content type, I see the 2 new content types are created (and Published) at admin/content/node. But they are not in my root node. Is there a way I can associate them with with the root node and have links for them show up in my edit node page?

• What happens to nodes that have been already created with a given root content type. If you go in and edit the root content type, it doesn't create the associated additional nodes. Can it be done? Is this a feature request for Version 3?

Thanks again for a cool module.

Comments

sunset_bill’s picture

Assigned: Unassigned » sunset_bill

Hey, thanks. Stuff like this is always good to hear. :-) What it sounds like you're asking is if there's a way to edit the referred (associated) nodes from the referring (root) node?

I'm pretty sure this could be done somehow, probably using workflows since the referred nodes aren't created until you hit 'Save' when creating the referring node...guess the edit page for an existing node with an ANR field could somehow include a link to the edit page for the referred node, or use the same workflow process to allow editing of referred nodes after the referring node has been edited. (BTW, if you want to replace a referred node, just delete it, go to the edit page for the referring node and hit Save--this will autocreate a new reference)

Hmm, gotta let that idea percolate for awhile and see what comes out. It didn't matter when I started out and was only using the module to create webforms to go along with the Corporate Reviews on rageagainstthecubefarm.com, but other content type template nodes necessarily have to be pretty generic and boring and the kind of thing that does need some additional editing.

salud...

mcfilms’s picture

Yes you get me exactly. After the root node creates the cloned nodes, when you return to the root node, you have links to the children (clones). Since they are all created at about the same time, I thought maybe you could rely on the node ID and just link to an increment of one or two above the current NID. But that seems dangerous. What if someone else is creating content at the very moment you save your node. Or what if, as you say, nodes get recreated later.

I wonder if there is a way to glue together what you are doing with http://drupal.org/project/nodereference_url Node reference URL widget.

Or maybe even better is the Prepopulate module http://drupal.org/project/prepopulate . do you think there is a way to create those cloned nodes but pass them an ID that will unify them all using Prepopulate?

Another possibility I considered is a "Master Page" in front of all this. It's sole purpose would be to create all the pages at once. But that still doesn't solve the problem of linking to a page that does not exist yet.

This is a very "meta" problem.

sunset_bill’s picture

Actually, it turns out to be a really fargin' simple hack but I'm too lazy to bother with all the CVS to make a new release right now. It really is stupid simple, though.

In autocreate.module, find the line

$ref_node = anr_clone_node($item, $node);

and change it to

$ref_node = anr_clone_node($item, $node);
if ($ref_node->nid){
drupal_set_message(l("edit $ref_node->title", "node/$ref_node->nid/edit"));
}

When the confirmation message comes up to tell you your root (or referring) node has been created, it will include links to edit forms for any child nodes that were autocreated at the time. No need for workflows or anything else. Note that this will only work when the referred (child) node is initially created. You also do NOT want to change the title of the referred node or ANR won't be able to find it later.

have fun,
SB

mcfilms’s picture

Thanks Sunset Bill,

I know almost enough php to understand what's going on there. Nonetheless, I am impressed with your codesmanship. (Is that a word?)

Unfortunately I reeeeeealy need to return to those subnodes (probably again and again). Is it possible instead of drupal_set_message() to use something like drupalCreateNode()? Would this create a node with the links in it? Of course even if that works, I still don't know how to hook it together so an end user can go from editing one sub node to the next. But it's worth thinking about. In my research for this, I found tons of people interested in a way to string a series of node creation forms together and have them all be associated with each other.

Oh and P.S. I just found this, so editing my post... What about a project to create the reference to the nodes? See http://www.darrenmothersele.com/drupal-blog/node-reference-create-drupal...

I realize I keep trying to foist a collaboration on you. But I think your node-cloner and his node link creator could be an unbeatable combination. Peanut butter, meet Jelly.

sunset_bill’s picture

Damn, do you know if that module was ever released? I did hours of searching and asking on forums for something like this before trying to write my own, nor could I figure out how to work my code into the Node Reference module. I could have saved myself hours of frustration, and I'd probably still have no idea how to write a Drupal module and we wouldn't be having this discussion. ;^)

Anyway, in its standalone way, ANR is specifically intended to do just what Darren's Node Reference enhancement does--create a node reference to a piece of content that doesn't exist yet. The big difference is that in ANR the node to be cloned for the reference is specified by the admin in the ANR field config in Content Type management, instead of by the user in the node/add form as it's done in Node Reference, but we're both creating a reference to something that doesn't exist yet by making a copy of a piece of existing content and then referencing the copy.

It seems to me that the best way to link a series of node edit forms together would be some logic in a hook_form_alter() to check for referenced nodes and add links in the edit form to the edit forms for the referenced nodes, but I admit to no competence at all with hook_form_alter() at this time. This could work in an edit form for an existing node, but the referred node doesn't exist yet when you're creating new content--the cloning doesn't happen until you hit Save, so there's nothing to link to until the confirmation stage, where that drupal_set_message() comes in.

No worries on the collaboration thing. I don't really have the time to work on this much right now, but the beauty of open source is that any and all are free to do with it as they will. I've got no objection at all to cool and useful patches. >>;;

mcfilms’s picture

I guess yours and that one do hold a lot in common. But as far as I can tell, that one was never released or reviewed. Maybe my analogy of Peanut Butter and Jelly would be better with the joining of ANR with Associated Nodes and Associated Links: http://drupal.org/node/400240

ANR would create several different clones of existing nodes.
Associated Nodes would associate the nodes according to a CCK field set in the parent
Associated Links would allow you to link to these individual pages from the parent

Does that make sense? The only thing I am still unclear on is how to pass that keyword to the cloned nodes that ANR creates. Is there a way to do that?

sunset_bill’s picture

Hmmmm, I'm thinking this is a bit out of the scope of what ANR is doing. Its sole purpose in life is to create a node to reference where none existed before. If it were possible at all, it would have to be the CCK form somehow passing an argument to the ANR field at creation time. Once the reference has been created, ANR is done.

I'm really not doing much with this module right now, so be warned that nifty features like the above are a long way off if at all. Meanwhile, of course, anybody who wants to hack in some improvements is invited to do so. ;^)

elfur’s picture

For future reference and a fuller picture, the Node Reference Create module has now been released:

http://drupal.org/project/noderefcreate

HTH
Elfur

Anonymous’s picture

I'm looking for instructions on using this great module.
What widget is supposed to appear?
Does it only work if 'autocomplete' is chosen for the nodereferenced field?
I don't see permissions for it in Permissions; or any place to Administer it.
Maybe it's working in the background, because when I add content to an existing nodereferenced field, Drupal doesn't barf. But the content does not then show up as a node of the content type being nodereferenced.

thank you

sunset_bill’s picture

Full instructions for Autocreate Node Reference are at http://drupal.org/node/371518

From your question #2, it sounds like you might be getting Autocreate Node Reference confused with Node Reference Create, which does something similar but a bit fancier. Briefly, ANR automatically makes a clone of an existing template node and creates a node reference to the cloned node in the parent node. Node Reference Create lets you create the referenced node if it doesn't exist yet.

HTH,
SB

rulick’s picture

Hey!

Thanks for such a great module. It is very helpful in managing CCK nodes.

I was wondering if it's possible to store the referred nid somewhere for future use? It's around the same place in the code as above in this thread: function autocreate_field() , where you call anr_clone_node(). I tried:

if ($ref_node->nid){
$node->$field['field_name'][0] = $ref_node->nid;
drupal_set_message(l("edit $ref_node->title", "node/$ref_node->nid/edit"));
}

But it did not help. What am I missing? It could be a simple PHP / Drupal question.

Ideally, I am looking at copying some fields from the original node. It could be a great addition to the way the module clones from AC_TEMPLATE.