Setting up Entity Reference content types, fields, views with Entity Reference Prepopulate add links

First, modules:

  • Views + CTools
  • Entity Views Attachments
  • Entity Reference 7.x-1.0-rc1
  • Entity reference prepopulate 7.x-1.0
  • References dialog 7.x-1.0-alpha3

Then, content types and fields:

  • Create four or more content types. For this example, I will use Client, Work, Task, and Note. Tasks and Notes can be 'attached to', e.g. entity reference, Client and Work nodes. Also, Work nodes can be attached to Clients. In my use case, I have several other content types, which can 'have' Tasks and Notes as well. The other content types in my use case also have entity references to Client and Work nodes.
  • Client is the ultimate parent content type, so you don't need any entity reference fields on it (unless you want them for some other purpose, of course).
  • On the Work content type, create an Entity Reference field using the autocomplete widget, called 'Client'. You can make it required if you want, but it does not have to be.
    • Check the "Enable Entity reference prepopulate" box, select "Disable field" for Action and "Do nothing" for Fallback behaviour. I usually set Skip access permission to "Administer site configuration".
    • If you want to enable the References Dialog widget to be able to add/edit a Client from the node add page for a Work, check the Edit and Add dialog boxes

  • In the 'Client' field settings, leave the Number of values at 1, Target type is "Node", and select "Client" for the Target bundles

  • Now, on the node add page for the Work content type, you will see the Client Entity Reference Field, with the Add Client link supplied by the References Dialog module:

  • Then, on your Task and Note content types, create (separate) Entity Reference fields called 'Attached to' (machine names: field_task_attachedto and field_note_attachedto), that can reference an unlimited number of Client, Work, and whatever other content types that you desire. You should use different fields for ease of management, but the settings are the same.
    • Check the "Enable Entity reference prepopulate" box, select "Disable field" for Action and "Do nothing" for Fallback behaviour. Set Skip access permission to "Administer site configuration".
    • You will not be able to use the References Dialog links since you are enabling the field to reference an unlimited number of different content types. With child content like "notes" and "tasks", you presumably are not going to be creating a parent, like a "client", when you are creating a "note" for the "client" - the "client" parent node will already exist.

  • In the Attached to field settings, select "Unlimited" for the Number of values, set the Target type to "Node", and select the Client, Work and any other content types to which you want to be able to attached Notes and Tasks under Target bundles.

  • Remember to create your "Attached to" Entity Reference field on both your Note and Task content types. If you recycle the field, it will have the same settings for both Notes and Tasks, so if you want to be able to attach Notes, but not Tasks, to some content types, then use two separate fields with the same settings.
  • First, create your Views to display the Notes and Tasks attached to a referencable node being viewed. I also have pages to display all of the Notes and Tasks, but I want to be able to see all of the Notes and Tasks attached to a Client or Work on the Client and Work nodes. Here, Entity Views Attachments (which is a great and useful module) comes into play. I'll use the example of Tasks again, but the process is basically the same for Notes - just change anything that was specific to Tasks to Notes when creating that View.
    • At admin/structure/views, click the "Add new view" link, name it something like "Attached Tasks" and select Show Content of type Task. Uncheck create a page, and leave create a block unchecked.
    • Use the "+Add" button near the top, to add an "Entity content" display to your newly created View
    • Under the "Entity Content Settings" pane, select "Node" for the "Entity type", and select the content types that can be referenced by the "Attached to" Entity Reference field on the Task content type (e.g., Client, Work, etc.). Leave Arguments at id. I opted to display the title of the View display by selecting "Yes" for Show title.
    • Add the fields that you want to display. Title is fine for now.
  • Then create your contextual filter, so that this Entity Views Attachment display only shows on content types referencable by the Attached to field on the Task content type, and to show only the Tasks that are attached to the node being viewed.
    • Expand the "Advanced" pane, and click the "add" button next to Contextual Filters to add your new Contextual Filter.
    • Select the "Attached to" field (machine name: field_task_attachedto), which will be listed as "Content: Attached to (field_task_attachedto)" to use as the Contextual Filter.
    • Under When the Filter in Not Available, select the "Provide default value" radio button, and then select "Content ID from URL".
    • Under When the Filter Value is Available or a Default is Provided, check the "Specify validation criteria" radio button, select "Content" for the Validator, and then select all of the content types that can be referenced by the Attached to field on Tasks (Client, Work, etc.). 
    • Leave the select list option for Action to take if filter value does not validate to "Hide view", which is the default and the desired behavior.
    • Click the apply button to save the new contextual filter that makes the magic happen!

Basic Entity Content View Display set-up:

Configuration for Contextual Filter on Content: Attached to (field_task_attachedto):

  • Now, after saving your new View, you will see Tasks listed on the nodes that are "attached to"/referenced by Tasks. Note, there is currently a bug in Entity Views Attachment that does not automatically make the Entity Content display available on content types. First go to the "Manage fields" tab for the content types, and then go to the "Manage display" tab. You should now see the Entity Content display field for the View you created, and you can position it where you would like in relation to any other fields. Here is a shot of what a Client node should look like, after you have created the Client and an attached Task:

  • Repeat the basic process of creating the EVA View to display Tasks attached to a node for the Note and Work content types. You can also display the View in a block instead of an EVA, which will allow you to display the child content type attached to a node in the sidebar or other regions of your theme.
  • Next, create the Views to be able to display "Add new [child_content_type]" links on parent nodes. Like with displaying the child content on parent nodes, you can use an EVA or a block to display the "Add new [child_content_type]" links on the parent nodes. This example will use creating the link in an EVA for the Tasks content type, but the basic process can be repeated for Notes, Works, or any other child content types - just make sure to use the correct fields and filters applicable to the work. Finally, Entity Reference Prepopulate comes into play:
    • At admin/structure/views, click the "Add new view" link, name it something like "Add new child links" and select Show Content of type All. Uncheck create a page, and leave create a block unchecked.
    • Use the "+Add" button near the top, to add an "Entity content" display to your newly created View
    • Under the "Entity Content Settings" pane, select "Node" for the "Entity type", and select the content types that can be referenced by the "Attached to" Entity Reference field on the Task content type (e.g., Client, Work, etc.). Leave Arguments at id. I opted to not display the title of the View display by leaving "No" set for Show title.
    • Add the "Content: Nid" field to your View, and remove the Title field.
    • For your filters, set the "Content: Type" filter to show only the content types that can be referenced by your "Attached to" field on the Tasks content type.
    • Change the page options so that you only display one piece of content (which will happen automatically once you set the contextual filter for this view).
  • Now, you need to set up your contextual filter on this display so that it is used only in the context of a node which can be referenced by your "Attached to" field on the Tasks content type.
    • Expand the "Advanced" pane, and click the "add" button next to Contextual Filters to add your new Contextual Filter.
    • Select "Content: Nid", listed as "Content: Nid" to use as the Contextual Filter.
    • Under When the Filter in Not Available, select the "Provide default value" radio button, and then select "Content ID from URL".
    • Under When the Filter Value is Available or a Default is Provided, check the "Specify validation criteria" radio button, select "Content" for the Validator, and then select all of the content types that can be referenced by the Attached to field on Tasks (Client, Work, etc.). 
    • Leave the select list option for Action to take if filter value does not validate to "Hide view", which is the default and the desired behavior.
    • Click the apply button to save the new contextual filter, and then save your view.

Basic Entity Content Views Display set-up:

Contextual filter configuration:

  • The final step on this View to make it usable is to rewrite your NID field so that it is output as a link on a parent node to add a new Task node with its "Attached to" field properly referencing the parent.
    • Click on the "Content: Nid" field, and uncheck the "Create a label" box
    • Expand the "Rewrite Results" section, and check the "Rewrite the output of this field" box
    • In the Text box, enter <ul><li><a href="/node/add/task?field_task_attachedto=[nid]">Add new Task</a></li></ul>
    • In the node/add/task part of the above, 'task' is the machine name of the child content type Task, and field_task_attachedto is the Entity Reference field on the child content type that can reference the parent node being viewed. Basically, with Entity Reference Prepopulate, the above link tells Drupal to go to the create new node page for a Task with the "Attached to" field pointing to the parent node being viewed. For the Notes content type and its "Attached to" field, the rewritten link will look like <ul><li><a href="/node/add/note?field_note_attachedto=[nid]">Add new Note</a></li></ul>

Now, when viewing a parent content type like a Client, you will see the Tasks attached to that client, and a link to add a new Task node from the Client. Once the Views for the Note content type are set-up, you will see the whole deal:

Drupal version: 

Comments

Thank you for the very nice

Thank you for the very nice article... I know D7 well enough to know that this is a very well written article... but I'm a newbie enough to not be able to understand after 2 readings... I wish there was a simpler version with just one parent type and one child type... But I guess you wanted to make a point, and which is as important as the one that would have met my needs for now, to have two child nodes referring to one or more parent nodes at the same time... I will have a read it again.. but I am sure this is what I was looking for in the first place... thanks much...

hermes belt

Thank you a lot for giving everyone a very breathtaking possiblity to read from here. It really is so kind and also jam-packed with a lot of fun for me and my office peers to visit your website at the very least three times weekly to see the latest items you have got. And of course, we're always fascinated with your attractive methods you serve. Selected 1 facts on this page are certainly the finest we have ever had.

Add new comment | arxic Drupal

I just could not depart your website prior to suggesting that I
actually enjoyed the standard info an individual provide on your guests?
Is gonna be again steadily to investigate cross-check new posts

kobe shoes

Needed to draft you this very little word to be able to thank you so much again about the pleasing opinions you have discussed in this article. It has been simply extremely open-handed of people like you to deliver unreservedly all most people would've distributed for an electronic book to generate some dough for themselves, chiefly considering that you could possibly have done it if you decided. These pointers likewise acted like the fantastic way to understand that some people have the same zeal like mine to understand a good deal more on the topic of this matter. I think there are several more fun moments ahead for many who look into your website.

Add new comment | arxic Drupal

When I originally commented I clicked the "Notify me when new comments are added" checkbox
and now each time a comment is added I get several emails with the same comment.
Is there any way you can remove people from that
service? Appreciate it!

golden goose outlet

My spouse and i were absolutely glad when Raymond managed to deal with his basic research with the precious recommendations he came across from your own web page. It's not at all simplistic just to possibly be making a gift of helpful tips that other people have been selling. And we acknowledge we have the writer to thank for that. The explanations you have made, the easy site menu, the friendships you will make it easier to create - it's got most overwhelming, and it's making our son and us recognize that that theme is interesting, which is especially serious. Thanks for the whole thing!

goyard handbags

I'm just commenting to make you understand of the perfect encounter my friend's child obtained going through your blog. She picked up so many things, which include what it is like to have a great coaching mood to make most people completely know just exactly certain hard to do matters. You really surpassed visitors' expectations. Thanks for imparting the effective, trusted, revealing not to mention easy tips on the topic to Sandra.

lebron 17

I am only commenting to let you know what a fantastic experience my cousin's princess had reading through your web site. She realized lots of pieces, with the inclusion of what it's like to possess a marvelous teaching spirit to make others completely gain knowledge of some problematic topics. You undoubtedly exceeded our own expectations. Many thanks for displaying these useful, trustworthy, edifying and even easy tips on that topic to Lizeth.

goyard

My wife and i were really satisfied when Louis could complete his homework because of the ideas he gained from your own web pages. It is now and again perplexing to simply continually be offering points which the others have been selling. And now we grasp we have you to appreciate for this. The entire illustrations you have made, the straightforward blog menu, the friendships your site give support to foster - it's everything superb, and it's really assisting our son and the family feel that the subject is cool, and that is tremendously indispensable. Many thanks for all!

supreme outlet

I am only writing to make you understand of the useful experience my friend's girl experienced viewing your web site. She noticed a good number of things, which included what it's like to possess an incredible helping style to make most people with no trouble fully understand several impossible subject matter. You undoubtedly exceeded my expectations. Thanks for providing those invaluable, trustworthy, edifying not to mention cool thoughts on your topic to Lizeth.

golden goose outlet

I'm just writing to let you understand what a amazing discovery my friend's child had reading through your site. She realized such a lot of details, with the inclusion of how it is like to have an amazing giving spirit to make a number of people effortlessly fully grasp a number of complicated issues. You actually did more than my expected results. Thanks for presenting the warm and helpful, safe, informative and even unique guidance on your topic to Sandra.

kobe shoes

I would like to express some appreciation to this writer just for bailing me out of this particular challenge. Because of scouting through the online world and finding proposals which were not helpful, I assumed my entire life was over. Being alive without the presence of approaches to the difficulties you've fixed through your main article content is a serious case, as well as ones which might have in a wrong way affected my career if I hadn't discovered the website. Your actual knowledge and kindness in handling everything was excellent. I'm not sure what I would've done if I hadn't come across such a solution like this. It's possible to now look forward to my future. Thanks very much for the reliable and effective guide. I will not think twice to refer your blog to anybody who should have assistance about this topic.

jordan shoes

Thanks for each of your efforts on this web page. Betty takes pleasure in working on research and it's obvious why. A lot of people know all of the dynamic manner you offer very important guidelines on this web site and as well as improve contribution from other ones on that content plus our princess is understanding a great deal. Enjoy the remaining portion of the new year. You are doing a really great job.

moncler jacket

Thank you a lot for giving everyone an extremely splendid chance to read from this web site. It is always so good plus packed with a great time for me personally and my office mates to visit your blog at minimum 3 times per week to study the new stuff you will have. And of course, we are always fascinated with your amazing inspiring ideas you give. Selected two tips in this posting are without a doubt the very best we have had.

mbt shoes

Thank you for all of your efforts on this web page. Kate takes pleasure in getting into investigation and it is easy to see why. I learn all about the compelling tactic you provide very useful solutions by means of your web site and as well strongly encourage response from other individuals about this theme and our own simple princess is actually becoming educated a lot of things. Have fun with the remaining portion of the new year. You're the one carrying out a really good job.

supreme outlet

Thank you a lot for providing individuals with such a memorable chance to discover important secrets from this site. It is often very fantastic and stuffed with a good time for me personally and my office acquaintances to visit your web site nearly thrice in 7 days to find out the newest items you have. Of course, I am just at all times impressed for the effective points served by you. Certain 4 areas in this article are in truth the most beneficial we have all had.

off white hoodie

I must show my appreciation for your kind-heartedness for individuals that should have help with that area of interest. Your personal dedication to passing the message all over came to be especially informative and has consistently made people much like me to realize their objectives. Your personal insightful guideline implies a whole lot a person like me and additionally to my colleagues. Thank you; from everyone of us.

adidas ultra boost

I simply desired to thank you so much once more. I do not know the things that I might have accomplished without these pointers documented by you relating to this area of interest. It was a very daunting crisis in my circumstances, nevertheless being able to see a new skilled form you solved it forced me to cry with fulfillment. Extremely happy for your work and thus wish you comprehend what an amazing job you're providing educating some other people thru a web site. I am certain you haven't encountered all of us.

michael kors outlet online

I must express thanks to you just for rescuing me from this type of condition. Right after searching throughout the the net and coming across recommendations which were not pleasant, I thought my entire life was well over. Being alive devoid of the approaches to the problems you have fixed as a result of your short post is a serious case, and the ones that could have in a negative way affected my career if I hadn't noticed your website. Your own personal talents and kindness in handling every item was precious. I don't know what I would've done if I had not discovered such a stuff like this. It's possible to at this point look ahead to my future. Thanks so much for the impressive and effective guide. I won't think twice to recommend the sites to anyone who needs and wants guidance on this subject matter.

balenciaga

Thank you for each of your effort on this web site. Gloria enjoys doing research and it is simple to grasp why. A lot of people hear all of the powerful method you convey effective thoughts by means of your website and therefore welcome contribution from other people on this content while our favorite daughter is always studying so much. Have fun with the remaining portion of the year. Your doing a tremendous job.

kyrie 3

I simply needed to thank you very much again. I'm not certain the things I might have gone through in the absence of those secrets contributed by you regarding such a theme. It seemed to be a real horrifying scenario in my opinion, but encountering the skilled style you dealt with it took me to leap for delight. Extremely happy for this guidance and then have high hopes you realize what a great job you are always carrying out educating the mediocre ones with the aid of your web site. More than likely you've never come across all of us.

yeezy shoes

I抦 impressed, I need to say. Really rarely do I encounter a blog that抯 each educative and entertaining, and let me tell you, you may have hit the nail on the head. Your idea is outstanding; the issue is something that not enough persons are talking intelligently about. I'm very comfortable that I stumbled throughout this in my seek for one thing regarding this.

golden goose

I actually wanted to jot down a note to be able to thank you for all of the marvelous advice you are showing at this website. My time consuming internet search has at the end been honored with incredibly good ideas to write about with my contacts. I would mention that many of us readers are definitely lucky to exist in a wonderful place with so many perfect people with very helpful guidelines. I feel really lucky to have seen your web pages and look forward to some more amazing times reading here. Thanks a lot once again for a lot of things.

christian louboutin outlet

I precisely had to appreciate you once again. I do not know the things that I might have handled without the actual methods contributed by you over that subject. Entirely was an absolute terrifying condition in my position, however , looking at the professional fashion you processed that made me to leap for contentment. I'm happy for your work as well as hope you are aware of a great job you are accomplishing training people with the aid of your site. I am sure you've never got to know any of us.

air max 270

Thank you a lot for providing individuals with such a marvellous opportunity to check tips from this website. It really is very beneficial and jam-packed with a lot of fun for me and my office colleagues to visit your web site nearly three times weekly to read the new guidance you have got. And definitely, I'm just always astounded with all the good techniques you serve. Selected 3 points in this post are certainly the simplest I have ever had.

Add new comment | arxic Drupal

Hi, i think that i noticed you visited my website thus i got here to go back the favor?.I am
attempting to to find things to improve my web
site!I suppose its good enough to make use of some of your ideas!!

irving shoes

I precisely desired to thank you very much yet again. I do not know the things that I would have tried without those information shared by you over my field. It truly was a real intimidating dilemma in my opinion, but taking note of this skilled style you treated it forced me to weep over happiness. I'm just thankful for your work and then sincerely hope you really know what a powerful job your are doing educating many others using your web page. I'm certain you have never met any of us.

fitflop

Thanks so much for providing individuals with a very marvellous chance to read critical reviews from here. It is always very useful and as well , jam-packed with fun for me and my office peers to search your site at least thrice per week to see the newest secrets you have. And indeed, I'm usually pleased with your surprising creative concepts you serve. Certain 2 facts in this post are in truth the most efficient we have all ever had.

nike air max 97

I am only commenting to let you understand of the outstanding discovery my friend's daughter had reading the blog. She even learned many issues, with the inclusion of how it is like to have an amazing teaching spirit to let the mediocre ones without hassle understand a number of specialized subject areas. You actually surpassed readers' desires. I appreciate you for offering these productive, healthy, edifying not to mention unique tips about this topic to Jane.

jordan shoes

I simply needed to thank you so much yet again. I do not know what I could possibly have used without those creative concepts contributed by you on my area. It previously was a horrifying setting in my circumstances, nevertheless observing a well-written fashion you resolved that made me to jump for happiness. I am thankful for the guidance and thus have high hopes you find out what a great job you have been doing training the rest via a web site. I know that you have never come across all of us.

balenciaga

My wife and i were quite relieved when Ervin could round up his basic research using the ideas he acquired in your blog. It's not at all simplistic to simply always be giving away points that other people have been making money from. We remember we need the writer to thank because of that. Those explanations you've made, the straightforward website menu, the relationships your site make it easier to instill - it's mostly impressive, and it's aiding our son and us feel that that issue is amusing, and that is exceedingly serious. Thank you for all!

air jordan

Thanks for all of your work on this web site. Ellie takes pleasure in setting aside time for investigations and it's easy to understand why. We hear all about the dynamic tactic you convey very helpful guidelines by means of your web site and even attract participation from people on the matter and my child is truly learning so much. Take pleasure in the remaining portion of the new year. You're the one performing a stunning job.

jordan shoes

I wanted to send a small message to appreciate you for the remarkable tips and hints you are giving here. My extensive internet research has at the end been rewarded with reputable knowledge to write about with my colleagues. I would express that we readers are very much endowed to live in a useful site with so many outstanding people with very beneficial opinions. I feel rather grateful to have used the webpage and look forward to many more exciting minutes reading here. Thank you once more for a lot of things.

kobe shoes

I precisely wanted to appreciate you all over again. I'm not certain the things I would have followed in the absence of the entire techniques provided by you concerning this topic. Entirely was an absolute horrifying problem in my circumstances, nevertheless looking at a well-written strategy you resolved it took me to cry with joy. I am just happier for the guidance and thus have high hopes you are aware of an amazing job you're getting into instructing some other people through a site. I am sure you haven't met any of us.

moncler jackets

I am only writing to make you be aware of of the brilliant discovery my princess had visiting your webblog. She even learned lots of things, which include how it is like to have a great helping nature to let many people smoothly learn a variety of complicated matters. You really surpassed people's desires. Thank you for providing these priceless, trusted, educational and as well as fun thoughts on this topic to Kate.

mbt

Thank you for each of your hard work on this website. My aunt enjoys going through research and it's really easy to see why. A number of us learn all of the lively way you present insightful guides on this website and therefore attract response from the others on the area of interest plus our own princess is undoubtedly discovering so much. Take pleasure in the rest of the year. You are doing a stunning job.

yeezy boost 350

I must show appreciation to this writer just for rescuing me from such a crisis. After researching through the the net and seeing views which were not helpful, I believed my entire life was done. Being alive without the presence of approaches to the problems you have solved by means of your entire article is a serious case, and the kind which might have in a negative way affected my entire career if I hadn't discovered your web blog. Your actual talents and kindness in touching the whole thing was invaluable. I am not sure what I would have done if I hadn't come upon such a point like this. I am able to now look forward to my future. Thank you so much for the reliable and result oriented guide. I will not think twice to propose your web blog to any person who requires assistance about this problem.

kyrie 5

I must show my appreciation to the writer just for rescuing me from this trouble. Because of exploring throughout the the net and obtaining techniques which are not pleasant, I assumed my entire life was well over. Being alive devoid of the strategies to the issues you've resolved as a result of your good guideline is a crucial case, as well as the ones which might have badly affected my career if I had not come across your blog. Your personal know-how and kindness in controlling the whole thing was invaluable. I don't know what I would've done if I had not come upon such a stuff like this. I can now look ahead to my future. Thanks a lot so much for the reliable and results-oriented guide. I will not hesitate to propose the sites to anyone who requires tips about this area.

kevin durant shoes

I definitely wanted to compose a remark to be able to say thanks to you for all the remarkable points you are posting on this website. My particularly long internet research has finally been recognized with excellent suggestions to share with my relatives. I would suppose that we visitors actually are unequivocally fortunate to dwell in a wonderful community with so many special professionals with interesting strategies. I feel quite fortunate to have come across the weblog and look forward to many more excellent times reading here. Thank you once again for all the details.

converse shoes

Thank you so much for providing individuals with an exceptionally wonderful opportunity to check tips from this site. It's usually so excellent and also full of amusement for me and my office colleagues to visit the blog at the very least three times in 7 days to learn the newest guidance you have. And lastly, I am certainly motivated considering the outstanding points you give. Some 2 ideas in this article are absolutely the very best we have ever had.

yeezy boost 350

Spot on with this write-up, I truly assume this web site needs much more consideration. I抣l in all probability be again to learn rather more, thanks for that info.

jordan shoes

I simply needed to thank you so much once again. I'm not certain the things I would've followed without these smart ideas provided by you on this subject. It had been the frustrating dilemma in my opinion, nevertheless considering the expert way you resolved it forced me to cry with happiness. I am happier for the guidance and even have high hopes you realize what a powerful job you are doing training most people with the aid of your blog post. I'm certain you have never encountered any of us.

nike huarache

I precisely needed to say thanks once more. I do not know what I might have accomplished without the information revealed by you on such a area of interest. It has been a frightening difficulty for me personally, but spending time with the well-written mode you dealt with it made me to jump with joy. I'm thankful for this help and in addition sincerely hope you realize what an amazing job you have been getting into educating people today via your web page. Most probably you have never got to know any of us.

Pages

Add new comment