Hi.

I have two content types: A and B. Both are custom content types using CCK. Both are used as book pages: B is a child node of A in the book outline, and there can be multiple B content submissions per A posting.

Is there a specific way that I can add a link somewhere on content type A display page that will open a "Add New B" form that is automatically associated "A" as its parent?

I need to display a link to all the "B" content types on the "A" page, but don't want users to have to figure out where in the outline B should go every time one is created.

Thanks for any suggestions!

Comments

Mark Theunissen’s picture

I've done this before. There's no easy way, but what I did was add a node reference field to the "B" type. Then I wrote a module that, when given the URL:

example.com/node/add/B/123

Would open the "add new node" form for content type B, and automatically populate the node reference field with "123".

Then I just build that link on every "A" page.

Do you want the module code? It's really short. I believe there's also another prepopulate module but not sure how that one works.

Hope that helps!

__________________________________________________________

Mark Theunissen

Code Baboon
Drupal based services

ext237’s picture

Yeah, that would be great, thanks! Seems like I wouldn't be the only person trying to resolve this issue, maybe you could even contribute it?

Mark Theunissen’s picture

Hang on a second - why don't you just use the book module in core?

book.module

__________________________________________________________

Mark Theunissen

Code Baboon
Drupal based services

ext237’s picture

This issue is adding the "B" pages as "A" children automatically. Having users trying to figure out where the children "B" pages go within the outline would be cumbersome and error prone. And guess who would get to clean up any missing/orphaned/misplaced pages? :)

Having a "Add a new B to this page." hyperlink on the "A" page will be a huge time saver for everyone.

Mark Theunissen’s picture

Ahh I see, well the problem then is that my code does this for a nodereference field - the book module uses it's own system to link pages. So you would be using two different systems.

But the book module provides a link already, when viewing a page. It says "add child page".

You could always make a custom link. If your book page was node/33, then your link to add a child page would be node/add/book/parent/33

Does that help?

__________________________________________________________

Mark Theunissen

Code Baboon
Drupal based services

ext237’s picture

Hmm ... maybe ... is there a way to set the child page to a custom content type?

ext237’s picture

Not really. I should have mentioned there may be more than one type of child content types.

In my example, I suggested content "A" needs a link to create a new child content "B" that automatically knows who its parent is.

However there will also need to be links to new content "C", "D" and "E" as well. Each child of the various content types need to know their parent on create so the user doesn't have to go looking.

Thanks for the suggestions and help!

Mark Theunissen’s picture

Does the book module let you use more than one content type? Sorry I haven't really tried.

The links would look something like :
/node/add/content_type_A/parent/122
/node/add/content_type_B/parent/122

etc.

__________________________________________________________

Mark Theunissen

Code Baboon
Drupal based services

Mark Theunissen’s picture

Ok, I have just tried and it doesn't look like the Book module allows more than one content type to be linked together.

So I would suggest you use a nodereference field to link CCK types, although in doing so, you'll have to do a whole lot of other stuff manually that is normally handled by the Book module, for example setting up views of your content to display it nicely (using Views module).

Have a look at the prepopulate module, I can't remember why I didn't use it, but it could work for you...

http://drupal.org/project/prepopulate

Otherwise I will contribute my module which is probably 20 lines but will need to be cleaned up to be made "generic" if you know what I mean.

__________________________________________________________

Mark Theunissen

Code Baboon
Drupal based services

MarcElbichon’s picture

I've created a module (BookMadeSimple) which can do this.

  1. You can automatically create a main book page for any content type (customized in admin section)
  2. It adds a dropdown listbox in book links to add any child content. Selecting the content type in the dropdown list box will add it as child page

For more explications, see BookMadeSimple home page or BookMadeSimple on code.google.com

fossie’s picture

Hello,

I use this combination for parent / child content, master / detail content building.

Create Custom content types
Create parent
Create child-1
Create child-2

Add node reference to child-1, child-2, this links to parent type

Add node_referrer with Content Addding to parent, refer to child-1.
Add another node_refferer with create to parent, refer to child-2.

This adds a link to create child content types from parent node view

You can use views to build a view (with the releated child nodes) and display this on the parent (with argument node_referrer and parent node nid).

(this child-1, child-2 is just in case you want to link to diferent related content to the parent)

I don't know if someons knows another possibility to accomplish this?

HTH,
Fossie

nickvu2’s picture

fossie, I think this is what I'm looking for!

Could you, or anyone else, explain this step to me:

Add node_referrer with Content Addding to parent, refer to child-1.
Add another node_refferer with create to parent, refer to child-2.

Is "node_referer" going to be the title of a CCK field? And are "content adding" and "create" settings? I'm looking around CCK and not sure what to do.

nickvu2’s picture

Got it, they're modules. Here are the links for future reference:

NodeReferrer (D5): http://drupal.org/project/nodereferrer
NodeReferrer (D6 only available as a patch at the time of this writing): http://drupal.org/node/259837#comment-1107282

Nodereferrer Create (D5 & D6): http://drupal.org/project/nodereferrer_create