4

I have the following scenario:

Content type A
Content type B

Content type A is added by the admin role.
Content type B is added by the students role.

Once Content type A is created, then on that link, like node/20 or content-type-A/20, I am looking to have an node add form for Content type B.

then the content type B that was added from this form, should be related and displayed with the existing content from content type A.

For example,
Content type A: title: Bread is good

So now, when you go to node/20 you see Title: Bread is good
then here you should have a form for Content type B with fields say title and some radio buttons. The student role user inputs the form and then submits.

Now the node/20 should display Title: bread is good and the fields associated with content type B that the student inputted.

And more students should be able to continue adding to this. This is something like a one-to-many relationship. Content type A has many Content type B associated with it.

I hope someone can help explain to me how to get this done

  • Content type A has many Content type B associated with it. If I put your sentence other way. It can be, "Content type -A node" will have many "Content type-B node" And it should be display like, First Content type-A node then all nodes added by students of Content type-B on that page. – CodeNext Jul 23 '16 at 2:40
3

For the first part of your problem you can use Entity reference to create the relation between the content types:

Provides a field type that can reference arbitrary entities:

  • A generic entity reference field
  • Four widgets:
    • Two implemented on top of the Options module (Select and Radios/Checkboxes),
    • Two autocomplete widgets (one with one text field per entry, one tag-style with comma-separated entries in the same text field)

For the second part, one content type form inside another content type form you have this modules:

The Inline Entity Form module:

Provides a widget for inline management (creation, modification, removal) of referenced entities. The primary use case is the parent -> children one (product display -> products, order -> line items, etc.), where the child entities are never managed outside the parent form. Existing entities can also be referenced.

Entityreference Autocreate

A deliberately simple way to invent nodes on the fly in order to refer to them via entityreference.

References dialog (beta2 release only)

This module extends reference fields like the user and node reference fields by adding links to add, edit and search for references through a dialog.

Autocreate Node Reference

Autocreate Node Reference adds a node reference field and automatically creates the referred node by cloning a template node.

Node Reference Create

Node Reference Create is an enhancement to the nodereference autocomplete widget that allows users to reference non-existent nodes.

Entity connect (rc5 release only)

It will help you to improve the User Experience for creation of new entities or edition of linked entities on your entity reference fields.

The "add a new" button will enable you to add / create a new entity. The first form will be cached then the new form will be generated. Once the new form is completed and saved the user will return to the original form.

Important: The module most used is Inline Entity Form, but it doesn't works with the Automatic Nodetitles module, but I know that Entity connect works fine with it. In addition with Entity connect you can edit existing entities. In my case I prefer Entity connect.

For the third part, the visualization of one entity (or more entities) inside another entity I think that you can use the EVA: Entity Views Attachment module, is very easy to use.

"Eva" is short for "Entity Views Attachment;" it provides a Views display plugin that allows the output of a View to be attached to the content of any Drupal entity. The body of a node or comment, the profile of a user account, or the listing page for a Taxonomy term are all examples of entity content.

I think that you should see this: Drupal 7 Node Reference Tutorial

2

Sounds like you could use Inline Entity Form with a reference field on type A to allow adding the type B nodes while viewing it, combined with some access control like Field Permissions. (If I'm not mistaken it should allow displaying the inlined node form while viewing the parent node, not just when editing it.)

For more layout flexibility I also suggest Display Suite and related modules.

  • I have tried using the Inline Entity Form on type A with a reference to type B. But this only allows you to add both type A and type B together. Even when I used Inline Entity Form, with the reference field, it created two node pages, one with type A, and another with type B and the reference. Still not as what we are tying to get to. Type A should be added, then type B should be added while viewing type A and that new data should be viewed with Type A from then. We are aiming for Type B to be like the comments system, users with a certain role can keep adding this type B data. – user2782792 Jul 23 '16 at 23:27
2

Once Content type A is created, then on that link, like node/20 or content-type-A/20, I am looking to have an node add form for Content type B.

You can use Form Block module to achieve this part.

now the node/20 should display Title: bread is good and the fields associated with content type B that the student inputted.

To link Content type A with content type B you have 2 possible ways:

Route 1 you will need to create a taxonomy vocabulary with terms, and add a tax term reference field. Then edit node A and B, and add the same term name.

OR

Route 2 Entity Reference and add a Entity reference field to content type B only. Then when the B form gets filled out you need to reference it to a node of type A. <------ This is the tricky part if you want this to be automatically filled with the nid of the content type A node you're on. You will have to use jQuery or a custom module (using hook_node_presave) to achieve this. Unfortunately, I don't have time to boot-up a D7 server and test a solution for this.

Now, create a block view, and under Advanced, Add Contextual filter of NID (content ID) and provide ID from url.

Add Relationship of Terms of the node (if you decided to go with route 1)

OR

Add Relationship of Referencing Entity (if you decided to go with route 2)

Lastly, Add/place block view to the content type A nodes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.