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.

cheap jordans

I simply wanted to compose a simple comment to be able to express gratitude to you for the nice suggestions you are giving out on this website. My incredibly long internet lookup has at the end been rewarded with excellent facts and strategies to share with my friends and classmates. I would declare that many of us website visitors actually are extremely fortunate to live in a fine community with very many wonderful professionals with good hints. I feel quite privileged to have come across your entire weblog and look forward to so many more pleasurable times reading here. Thanks a lot once again for a lot of things.

coach handbags

I wish to show my thanks to you just for bailing me out of this type of challenge. As a result of looking throughout the the web and getting tricks that were not powerful, I was thinking my life was gone. Existing minus the answers to the issues you have solved as a result of this website is a serious case, and the ones that could have negatively damaged my entire career if I hadn't come across your site. Your primary competence and kindness in controlling a lot of things was excellent. I am not sure what I would have done if I hadn't discovered such a subject like this. I am able to at this time look forward to my future. Thanks for your time so much for your high quality and sensible help. I won't think twice to refer the blog to anybody who will need care on this issue.

kd 11

I have to show some thanks to you for rescuing me from this type of matter. Right after scouting throughout the search engines and obtaining tips which were not beneficial, I was thinking my life was well over. Being alive without the presence of approaches to the difficulties you have fixed by means of your main short post is a serious case, and the ones which could have badly affected my career if I had not come across your blog post. That capability and kindness in playing with every part was important. I don't know what I would've done if I hadn't discovered such a point like this. I can now look ahead to my future. Thanks for your time so much for the reliable and result oriented help. I will not be reluctant to endorse your web site to any individual who needs and wants tips about this topic.

moncler coat

I must show my admiration for your generosity for men who need assistance with this area of interest. Your personal dedication to getting the solution all around appeared to be exceptionally important and has really helped somebody like me to reach their dreams. Your amazing informative guideline can mean so much a person like me and far more to my peers. Warm regards; from all of us.

golden goose

I precisely desired to thank you so much once again. I'm not certain what I might have worked on without the type of creative concepts documented by you about my subject. It was before a difficult setting in my view, nevertheless observing the very well-written mode you resolved it forced me to leap over happiness. I am happier for this service and then hope that you recognize what a powerful job you have been putting in educating other individuals through the use of your web page. I am sure you've never come across all of us.

supreme shirt

I and also my pals ended up examining the great tactics found on your website and before long developed an awful feeling I never thanked the website owner for those secrets. Those young men ended up as a result excited to see all of them and have now clearly been taking pleasure in these things. I appreciate you for actually being so accommodating and then for deciding on some amazing themes most people are really desperate to be informed on. My personal sincere regret for not expressing appreciation to you sooner.

kobe shoes

Thanks a lot for giving everyone an extremely memorable possiblity to check tips from this site. It really is very beneficial and as well , full of a good time for me personally and my office colleagues to visit your site at least thrice every week to find out the fresh things you have. And of course, I am just at all times contented with all the perfect creative ideas you give. Some two tips in this article are without a doubt the most suitable I have ever had.

nike shoes

I happen to be writing to make you understand what a great discovery my princess found reading through your webblog. She realized several things, with the inclusion of how it is like to have an ideal helping nature to let other people completely fully understand some extremely tough issues. You undoubtedly exceeded visitors' expected results. Thank you for coming up with those necessary, healthy, educational and as well as unique tips about that topic to Ethel.

michael kors outlet

Thanks a lot for giving everyone remarkably marvellous possiblity to discover important secrets from this site. It's usually very sweet plus jam-packed with amusement for me personally and my office acquaintances to visit your site at the least thrice a week to study the new stuff you will have. And of course, we're at all times happy considering the cool opinions served by you. Certain 4 facts on this page are rather the most impressive we've ever had.

jordan shoes

I truly wanted to send a small comment to express gratitude to you for all the magnificent instructions you are sharing at this website. My time-consuming internet investigation has at the end been honored with sensible tips to talk about with my friends and classmates. I 'd express that many of us site visitors are quite lucky to be in a fine community with many awesome individuals with good tactics. I feel very much grateful to have encountered your webpages and look forward to really more enjoyable moments reading here. Thanks a lot once again for all the details.

moncler

I precisely needed to say thanks all over again. I'm not certain the things I would have worked on in the absence of those pointers discussed by you over such a field. Certainly was a difficult scenario for me personally, nevertheless being able to view your professional technique you managed that forced me to leap for delight. Now i am grateful for the guidance as well as wish you comprehend what a great job your are carrying out teaching people via your websites. Probably you haven't got to know any 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!

Pages

Add new comment