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

nike huarache

I definitely wanted to post a comment to express gratitude to you for all of the fabulous strategies you are posting here. My extensive internet look up has at the end been compensated with reputable concept to share with my great friends. I 'd declare that most of us visitors are very fortunate to dwell in a useful network with many special people with very helpful plans. I feel quite grateful to have used the website page and look forward to tons of more excellent moments reading here. Thank you once again for a lot of things.

golden goose outlet

I wanted to compose you one little note just to thank you very much as before for your personal precious tricks you have shared at this time. This is really unbelievably open-handed of people like you to give unreservedly all that many people could possibly have offered for sale as an e-book to end up making some bucks for their own end, most notably given that you could possibly have done it if you ever considered necessary. These principles as well acted as the great way to be certain that many people have similar dream similar to my personal own to learn a little more with respect to this issue. I am certain there are thousands of more enjoyable opportunities in the future for individuals that read your website.

golden goose

I have to show my appreciation to you for bailing me out of this type of issue. Because of surfing around throughout the world wide web and getting methods which are not helpful, I assumed my life was gone. Existing minus the approaches to the difficulties you have sorted out all through your entire short article is a critical case, and the ones which could have in a negative way damaged my entire career if I hadn't come across your blog. Your own personal understanding and kindness in playing with the whole thing was very helpful. I am not sure what I would have done if I had not come upon such a point like this. I can also at this time relish my future. Thanks a lot very much for this skilled and amazing guide. I won't think twice to endorse the sites to any individual who needs to have guidance on this matter.

cheap jordans

Needed to post you this very little note so as to give many thanks over again regarding the incredible basics you have provided on this website. It's so unbelievably generous with you to make openly exactly what numerous people would have advertised for an e-book to end up making some cash for their own end, mostly now that you might have done it if you desired. Those techniques also served like a great way to fully grasp that other individuals have a similar dream similar to my own to know a little more around this matter. I am sure there are several more enjoyable situations ahead for folks who see your website.

Add new comment | arxic Drupal

What i do not understood is in reality how you are no longer actually much
more well-favored than you may be right now.
You're so intelligent. You know thus considerably in relation to this
matter, made me for my part imagine it from a
lot of various angles. Its like men and women aren't interested unless it's one thing to
do with Girl gaga! Your personal stuffs great. Always care for it
up!

fila

I as well as my guys appeared to be reading the best secrets located on the blog then the sudden I got a terrible suspicion I never expressed respect to the web blog owner for those techniques. Those young men happened to be so stimulated to read all of them and already have definitely been tapping into those things. I appreciate you for truly being indeed considerate as well as for utilizing varieties of fantastic things millions of individuals are really desirous to know about. My personal sincere apologies for not expressing appreciation to earlier.

Add new comment | arxic Drupal

Outstanding post however I was wondering if you could write a litte more on this subject?
I'd be very thankful if you could elaborate a little bit more.
Cheers!

kyrie 5

I am glad for commenting to make you know of the fantastic experience my child obtained using yuor web blog. She figured out several details, including what it is like to have an ideal teaching spirit to get men and women really easily fully grasp several extremely tough subject matter. You actually did more than visitors' expected results. Thanks for imparting those good, dependable, informative not to mention easy tips about your topic to Julie.

Add new comment | arxic Drupal

It is the best time to make a few plans for the future and it is time to be happy.
I've read this put up and if I may just I wish to recommend
you some interesting issues or suggestions. Maybe you could write subsequent articles referring
to this article. I desire to learn more issues about it!

golden goose

I am only commenting to let you understand what a beneficial encounter my princess went through visiting the blog. She learned too many details, with the inclusion of how it is like to have a wonderful giving mindset to get certain people very easily gain knowledge of a number of very confusing subject areas. You undoubtedly surpassed readers' desires. Many thanks for delivering these warm and helpful, safe, explanatory and even cool thoughts on your topic to Gloria.

Add new comment | arxic Drupal

I like the helpful info you provide in your articles.
I will bookmark your blog and check again here frequently.
I'm quite certain I'll learn plenty of new stuff right here!

Good luck for the next!

louboutin outlet

Needed to compose you a very small note to be able to give thanks the moment again for these splendid tips you have provided on this website. It's really open-handed with people like you to give publicly all that many of us might have marketed as an e-book in making some dough for their own end, notably seeing that you might have done it if you ever considered necessary. Those basics also worked to become great way to realize that other people have the same passion just like my own to realize great deal more with reference to this problem. I am certain there are some more fun instances in the future for folks who go through your blog post.

Add new comment | arxic Drupal

I like the valuable info you provide in your articles.
I will bookmark your blog and check again here frequently.
I'm quite sure I will learn many new stuff right here!
Best of luck for the next!

Add new comment | arxic Drupal

Greetings! Quick question that's completely off topic.
Do you know how to make your site mobile friendly?
My blog looks weird when viewing from my iphone 4.
I'm trying to find a template or plugin that might be able to fix this
problem. If you have any suggestions, please share.

Thanks!

Add new comment | arxic Drupal

Hi, i think that i saw you visited my blog thus i came to “return the favor”.I'm attempting to find things to improve my website!I suppose its ok to use
some of your ideas!!

Add new comment | arxic Drupal

My partner and I stumbled over here coming from a different web address and thought I should check things out.
I like what I see so now i am following you. Look forward to looking into your web page again.

Add new comment | arxic Drupal

It's really a cool and useful piece of information. I'm happy
that you just shared this useful info with us. Please stay us informed like this.
Thanks for sharing.

vapormax

I抦 impressed, I need to say. Really hardly ever do I encounter a blog that抯 each educative and entertaining, and let me let you know, you've got hit the nail on the head. Your idea is excellent; the problem is one thing that not sufficient individuals are talking intelligently about. I'm very pleased that I stumbled throughout this in my seek for one thing referring to this.

jordan shoes

Nice post. I study one thing more challenging on totally different blogs everyday. It'll always be stimulating to learn content from different writers and follow slightly one thing from their store. I抎 prefer to use some with the content material on my blog whether you don抰 mind. Natually I抣l provide you with a link on your internet blog. Thanks for sharing.

Add new comment | arxic Drupal

I'm extremely impressed with your writing skills and also with the layout on your blog.
Is this a paid theme or did you customize it yourself?
Anyway keep up the nice quality writing, it's rare to see a great blog like this one nowadays.

off white hoodie

Youre so cool! I dont suppose Ive read something like this before. So good to search out someone with some authentic thoughts on this subject. realy thank you for beginning this up. this web site is one thing that is wanted on the web, somebody with slightly originality. helpful job for bringing one thing new to the internet!

Add new comment | arxic Drupal

It's actually a nice and helpful piece of information. I am
happy that you shared this useful info with us. Please keep
us informed like this. Thank you for sharing.

retro jordans

Nice post. I learn one thing more difficult on totally different blogs everyday. It will always be stimulating to read content material from different writers and practice a bit one thing from their store. I抎 favor to make use of some with the content material on my weblog whether you don抰 mind. Natually I抣l give you a hyperlink in your web blog. Thanks for sharing.

adidas gazelle

Spot on with this write-up, I actually think this website wants rather more consideration. I抣l probably be again to learn rather more, thanks for that info.

Add new comment | arxic Drupal

Today, while I was at work, my cousin stole my iPad and tested to see
if it can survive a 30 foot drop, just so she can be a youtube sensation. My iPad is now broken and she has 83 views.

I know this is completely off topic but I had to share
it with someone!

nike foamposite

I simply had to appreciate you once more. I'm not certain what I might have used in the absence of these opinions documented by you concerning my field. It seemed to be the depressing crisis in my view, however , encountering your professional strategy you treated that forced me to leap with fulfillment. I'm just happier for the support as well as hope you realize what an amazing job that you are undertaking educating other individuals all through your website. I'm certain you have never come across any of us.

golden goose

I simply wanted to post a small note to be able to appreciate you for these nice suggestions you are showing at this site. My rather long internet look up has at the end been honored with good quality facts and strategies to exchange with my friends and classmates. I 'd express that we readers actually are undoubtedly endowed to dwell in a wonderful network with so many special individuals with beneficial plans. I feel truly fortunate to have used the webpages and look forward to plenty of more fabulous moments reading here. Thank you once again for a lot of things.

Add new comment | arxic Drupal

Definitely believe that which you said. Your favorite reason seemed
to be on the internet the simplest thing to be aware of.
I say to you, I definitely get annoyed while people consider worries that
they plainly don't know about. You managed to hit the
nail upon the top as well as defined out the whole thing without having side-effects , people can take a signal.
Will likely be back to get more. Thanks

nike shox for women

I must express my thanks to you just for bailing me out of this type of condition. Because of looking through the online world and seeing tips which are not beneficial, I thought my entire life was gone. Being alive minus the strategies to the problems you've fixed all through your main posting is a critical case, as well as the ones which may have in a negative way affected my career if I had not encountered your web page. Your primary competence and kindness in maneuvering all the things was priceless. I'm not sure 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 so much for the professional and results-oriented guide. I won't be reluctant to propose your blog to anyone who should get assistance on this problem.

Add new comment | arxic Drupal

With havin so much written content do you ever run into any problems
of plagorism or copyright violation? My website has a
lot of unique content I've either authored myself or outsourced but it seems a lot
of it is popping it up all over the web without
my permission. Do you know any ways to help reduce content
from being ripped off? I'd certainly appreciate it.

off white x jordan 1

Thank you a lot for giving everyone such a special possiblity to read in detail from this blog. It's always very beneficial plus full of a lot of fun for me and my office acquaintances to visit your site at the least three times per week to read the new things you have. And of course, I'm just certainly contented with all the fabulous inspiring ideas served by you. Selected two facts in this article are in fact the most impressive we've had.

Add new comment | arxic Drupal

I'm truly enjoying the design and layout of your website.
It's a very easy on the eyes which makes it much more enjoyable for
me to come here and visit more often. Did you hire out
a designer to create your theme? Exceptional work!

nike huarache

I'm also writing to make you understand of the extraordinary discovery my friend's girl found going through your blog. She realized such a lot of things, which included what it's like to possess an ideal helping mood to let the mediocre ones just master various tricky things. You undoubtedly surpassed our expected results. Many thanks for producing those precious, trustworthy, informative and cool tips about this topic to Tanya.

Add new comment | arxic Drupal

Having read this I believed it was rather enlightening.
I appreciate you spending some time and energy to put
this informative article together. I once again find myself personally spending way too much
time both reading and commenting. But so what, it was still worth it!

air max 270

Thanks so much for giving everyone remarkably pleasant opportunity to check tips from this site. It's always so enjoyable and packed with fun for me and my office mates to search your blog not less than 3 times every week to read the fresh guidance you have. Of course, we're at all times astounded considering the extraordinary principles served by you. Selected 4 ideas in this post are in reality the most efficient we have all ever had.

Pages

Add new comment