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...

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.

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.

fila

Good post. I study one thing more difficult on completely different blogs everyday. It's going to all the time be stimulating to read content material from different writers and apply a bit something from their store. I抎 favor to use some with the content on my weblog whether you don抰 mind. Natually I抣l give you a link in your web blog. Thanks for sharing.

curry 6

Good day! I simply want to give an enormous thumbs up for the great information you will have right here on this post. I can be coming back to your weblog for extra soon.

vapormax

I抎 should check with you here. Which isn't one thing I usually do! I enjoy reading a put up that may make individuals think. Additionally, thanks for permitting me to remark!

coach outlet store

Spot on with this write-up, I actually think this website needs far more consideration. I抣l in all probability be again to learn rather more, thanks for that info.

longchamp handbags

Thanks a lot for providing individuals with remarkably terrific opportunity to read articles and blog posts from this website. It is usually very good and as well , full of amusement for me and my office friends to visit your website the equivalent of three times weekly to find out the newest items you have. And lastly, we're certainly satisfied concerning the powerful information you give. Selected two facts on this page are easily the finest we've ever had.

yeezy boost 350

A lot of thanks for all of the work on this site. My mum really loves going through investigation and it is obvious why. Most people know all about the powerful manner you produce effective tips and hints on this blog and therefore increase participation from some others on this matter plus my daughter is without question studying so much. Take pleasure in the remaining portion of the year. You are always doing a really good job.

michael kors factory outlet

I want to show appreciation to you for bailing me out of this type of crisis. Right after checking throughout the world-wide-web and coming across opinions which were not powerful, I was thinking my life was over. Living without the presence of strategies to the difficulties you've resolved by means of your good blog post is a serious case, as well as ones which might have in a negative way damaged my entire career if I had not noticed your web blog. Your personal understanding and kindness in maneuvering the whole lot was vital. I am not sure what I would've done if I hadn't come across such a point like this. I am able to at this point look forward to my future. Thanks very much for the expert and result oriented help. I won't hesitate to refer the website to any individual who should get tips about this situation.

yeezy

I in addition to my pals came looking at the best things on the website while instantly I had a terrible feeling I had not thanked you for those techniques. All the people came for that reason joyful to read through all of them and already have seriously been tapping into those things. Thank you for turning out to be simply considerate and then for using such incredibly good resources millions of individuals are really desirous to be aware of. Our honest apologies for not expressing appreciation to you sooner.

supreme

I want to express my affection for your generosity supporting those people who need assistance with in this concern. Your personal commitment to passing the message all over came to be astonishingly advantageous and has truly made employees like me to reach their aims. Your entire insightful advice can mean a whole lot a person like me and far more to my mates. Best wishes; from all of us.

coach facotory outlet

I want to show thanks to you just for rescuing me from this difficulty. After scouting through the the web and seeing tricks that were not powerful, I figured my life was done. Being alive devoid of the approaches to the problems you have sorted out all through your entire write-up is a crucial case, as well as the ones that could have adversely affected my entire career if I had not discovered your web site. Your ability and kindness in playing with all the stuff was useful. I don't know what I would've done if I hadn't come across such a step like this. I'm able to at this moment look forward to my future. Thanks for your time very much for your reliable and sensible help. I will not hesitate to propose your web sites to any individual who needs and wants guidelines about this subject matter.

louboutin shoes

Thanks a lot for providing individuals with such a pleasant chance to read articles and blog posts from this blog. It is usually so sweet and packed with a lot of fun for me personally and my office mates to visit your website at a minimum three times weekly to read through the newest secrets you will have. And of course, I am at all times pleased concerning the exceptional concepts you serve. Certain 3 tips in this posting are basically the most impressive we have all had.

yeezy boost

Thanks for all of your efforts on this blog. My mom really loves participating in research and it's easy to understand why. Many of us notice all about the lively ways you produce reliable tactics through this web blog and as well strongly encourage contribution from other people on the article so my simple princess is always learning so much. Take advantage of the remaining portion of the new year. Your conducting a wonderful job.

adidas tubular

I together with my buddies have been going through the excellent recommendations from the blog and unexpectedly developed a terrible feeling I had not thanked the web site owner for those tips. Those boys became so very interested to read them and have now actually been taking pleasure in them. I appreciate you for actually being quite accommodating and for considering these kinds of good resources most people are really needing to know about. Our own sincere regret for not expressing appreciation to you earlier.

hermes handbags

I would like to express thanks to you for bailing me out of this condition. As a result of surfing through the world-wide-web and meeting tricks which are not helpful, I assumed my life was well over. Living devoid of the approaches to the difficulties you have sorted out by means of your good report is a critical case, as well as the kind which may have adversely damaged my career if I had not discovered the website. Your own ability and kindness in taking care of a lot of things was tremendous. I don't know what I would've done if I had not discovered such a thing like this. I can also at this point look ahead to my future. Thanks so much for this reliable and sensible guide. I won't be reluctant to refer your web page to anybody who requires support about this area.

hermes birkin

Thanks so much for giving everyone an exceptionally breathtaking possiblity to read from here. It is always so nice and stuffed with fun for me personally and my office friends to visit your web site more than 3 times in one week to see the latest guides you will have. Of course, I am just usually impressed with the extraordinary inspiring ideas served by you. Selected 3 ideas in this article are undoubtedly the very best we have all ever had.

nike air max

When I initially commented I clicked the -Notify me when new feedback are added- checkbox and now each time a remark is added I get 4 emails with the same comment. Is there any way you possibly can take away me from that service? Thanks!

balenciaga shoes

After research a couple of of the blog posts on your website now, and I really like your method of blogging. I bookmarked it to my bookmark web site list and will likely be checking back soon. Pls try my website online as effectively and let me know what you think.

nike air max 2017

Youre so cool! I dont suppose Ive read something like this before. So good to search out anyone with some authentic ideas on this subject. realy thanks for beginning this up. this web site is one thing that is wanted on the web, someone with a little originality. useful job for bringing one thing new to the web!

moncler

This is the correct blog for anybody who wants to seek out out about this topic. You understand a lot its almost exhausting to argue with you (not that I really would need匟aHa). You undoubtedly put a new spin on a topic thats been written about for years. Great stuff, just nice!

air max 90

I抎 need to check with you here. Which isn't something I often do! I get pleasure from studying a submit that will make people think. Additionally, thanks for allowing me to comment!

hermes belts

Can I just say what a reduction to find somebody who actually knows what theyre talking about on the internet. You positively know find out how to bring a problem to gentle and make it important. Extra folks must read this and perceive this facet of the story. I cant imagine youre no more popular since you positively have the gift.

nike shoes for men

That is the best blog for anybody who desires to find out about this topic. You understand a lot its nearly hard to argue with you (not that I really would need匟aHa). You definitely put a brand new spin on a subject thats been written about for years. Nice stuff, simply nice!

balenciaga shoes

I enjoy you because of your own effort on this web site. My mother really loves going through internet research and it's really obvious why. Most people know all concerning the compelling method you convey informative items by means of this web site and even strongly encourage response from visitors on that content plus my princess has always been discovering so much. Take advantage of the remaining portion of the year. You're carrying out a really good job.

nike kyrie 6

I am also commenting to let you know of the amazing experience my cousin's princess obtained studying your blog. She learned numerous issues, most notably what it is like to have a very effective coaching character to let a number of people very easily fully grasp some extremely tough matters. You actually surpassed visitors' expected results. Thank you for offering those great, trustworthy, informative and as well as easy tips on your topic to Sandra.

balenciaga shoes

I in addition to my buddies have already been checking the great suggestions on your site and so immediately got an awful feeling I had not thanked the web site owner for them. All the young men are actually certainly very interested to learn them and have in effect unquestionably been taking advantage of those things. Thank you for getting so accommodating and also for choosing some important ideas millions of individuals are really wanting to be aware of. My sincere regret for not expressing gratitude to you sooner.

balenciaga

Thanks a lot for giving everyone such a terrific opportunity to read critical reviews from this site. It can be very sweet and also jam-packed with amusement for me and my office friends to visit your website at least three times a week to read the newest stuff you have got. And of course, I'm certainly amazed concerning the astounding tips you give. Some 1 facts in this article are undoubtedly the simplest I've had.

jordan retro

I wish to get across my appreciation for your kindness supporting individuals that really want help on this particular subject matter. Your special dedication to passing the message all around has been exceptionally practical and have without exception permitted guys and women much like me to realize their pursuits. Your new useful help and advice signifies this much a person like me and additionally to my office colleagues. Many thanks; from everyone of us.

adidas yeezy boost

I precisely had to say thanks again. I do not know the things I would have made to happen in the absence of the tips shown by you on such a area. It absolutely was a distressing case for me personally, but being able to see a new expert form you treated the issue made me to weep over fulfillment. Now i'm grateful for the guidance and as well , pray you realize what an amazing job that you're carrying out training others through your blog post. I am certain you've never met all of us.

hermes handbags

I enjoy you because of all of the efforts on this website. Kim really loves carrying out research and it's really obvious why. A number of us know all about the lively way you convey invaluable tactics through this blog and in addition boost participation from other individuals on the article and our girl is certainly learning a lot of things. Have fun with the rest of the year. You are carrying out a really good job.

yeezy

I simply desired to thank you very much once again. I do not know the things that I would have implemented in the absence of the tactics discussed by you relating to that subject. This was a very hard case in my view, nevertheless witnessing this expert form you handled it made me to jump over gladness. Now i'm happy for this assistance and then wish you really know what a great job you have been undertaking instructing others via a site. I am sure you haven't got to know any of us.

supreme hoodie

I and also my guys were found to be going through the best tips and tricks found on your web blog while then I had an awful feeling I never expressed respect to the web site owner for those techniques. The young boys appeared to be glad to see all of them and already have very much been tapping into them. Many thanks for turning out to be so thoughtful and also for getting this sort of fabulous guides most people are really wanting to be informed on. Our own sincere regret for not expressing appreciation to you sooner.

fila online shop

I actually wanted to compose a simple word in order to appreciate you for the amazing ways you are giving here. My time-consuming internet investigation has now been honored with incredibly good points to write about with my company. I would claim that many of us site visitors are definitely blessed to be in a superb community with many awesome people with insightful plans. I feel truly fortunate to have used the web pages and look forward to many more entertaining minutes reading here. Thanks a lot once more for all the details.

Add new comment | arxic Drupal

My coder is trying to persuade me to move to .net from PHP.

I have always disliked the idea because of the costs. But he's tryiong
none the less. I've been using WordPress on several websites for about a year and am anxious about switching to another
platform. I have heard excellent things about blogengine.net.
Is there a way I can transfer all my wordpress posts into it?
Any help would be really appreciated!

coach outlet

I discovered your blog web site on google and test a few of your early posts. Proceed to keep up the very good operate. I simply further up your RSS feed to my MSN Information Reader. Seeking ahead to reading extra from you in a while!?

nike air max 270

An fascinating discussion is value comment. I feel that it is best to write more on this topic, it won't be a taboo topic but typically people are not sufficient to speak on such topics. To the next. Cheers

kobe sneakers

The following time I learn a weblog, I hope that it doesnt disappoint me as much as this one. I mean, I do know it was my option to read, however I actually thought youd have one thing fascinating to say. All I hear is a bunch of whining about one thing that you may repair if you werent too busy searching for attention.

jordans

you've got an ideal weblog right here! would you wish to make some invite posts on my weblog?

bape hoodie

I found your blog web site on google and test a couple of of your early posts. Continue to maintain up the superb operate. I just additional up your RSS feed to my MSN News Reader. Searching for ahead to studying extra from you in a while!?

Pages

Add new comment