BLUF:
(1) How do I display all nodes of a particular content type (e.g. Task) that are related to a specific node of another content type (e.g. Project) using Views?
(2) Using the example content types above, what is the best way to automatically populate the appropriate field in a new node of type Task so that the user does not and cannot mess up the reference?
This seems very basic to the core functionality of a CMS to me, but after days of reading books and forums and associated sites, I am asking for help. Using the same example, the site contains several nodes of type Project that, well, include the unique characteristics of a project, say, to "build a birdhouse." Each project includes many tasks. Tasks and their related characteristics are nodes of type Task. Examples of task nodes are "Obtain birdhouse plans" and "Buy birdhouse materials."
After some amount of reading and playing with a test site, I think the answer lies in the proper use of the Contextual Filters and Relationships settings of the Views module used in conjunction with the proper configuration of an Entity Reference field in the Task content type (being allowed from the Entity Reference module). My biggest problem is that all of the Views tutorials that I find appear to either be written for an older version of Views and the menu selections are all different or they only use the Contextual Filter for fields that appear to be built into core - and - I have found next to nothing to help with the configuration of Entity Reference fields.
Here is how far I have gotten: Using the Contextual Filter, I created a Views block that, when placed on a Project node page, will list the tasks for that project.
Specific questions: The verbiage in the dialog boxes for the Contextual Filter and Relationship configuration don't seem to make any sense. For example, when I initially select the filter on the Add Contextual Filters page, am I selecting the field being filtered or the field of the data that I am using to filter something else? And on the next page, why am I selecting a configuration for an instance when the filter value is not available? I got it to work with the Nid from the URL, but it did not make any sense to me based on the verbiage in the dialog boxes.
Also, how can I get a page view to replace the default node page, i.e. have selection of project link take the user to a Views page display rather than the default node page?
Third, what are the differences between the Select List and Autocomplete widget types for the Entity Reference field?
Fourth, what are the differences between the two Mode options in the Entity Selection dialog box for configuration of the Entity Reference field? I had assumed that I needed to select the Views option, but I don't know what is required for an "eligible" view to be created. I created a Views block with that field identified in a Relationship and it does not seem to recognize the View as "eligible."
Finally, and admittedly getting a little ahead of myself, when a user is viewing a project page and creating new tasks, how do I have those new tasks automatically linked to the project that the user is working on without the user having to populate the field manually? Is this a Rules solution or is there a simpler solution?
I am new to Drupal and started with 7.16, so references to D6 or changes in D7 are lost on me. I am not a mySQL or PHP or jQuery developer. I am hoping that the answer is something that I can configure in the admin pages or drush, but if it has to be a block of code, I need baby steps of what to do with it, what it does, and what it means.
I realize that this is a long post, but I wanted to be as specific as possible to prevent a lot of time-consuming replies to the wrong question. I have a lot of respect for the volunteers that have devoted so much to this community and am amazed at the product created. I hope that I will have the knowledge set one day to contribute to the effort. For now, I will continue to beat my head against the display and muscle my way to some answers, but any help you could provide would be greatly appreciated. Thanks in advance.
Comments
I am also looking for how to
I am also looking for how to display related fields from different node types.
One mystery solved... (of many:)
Sorry, I could not help myself.
I did figure out why I am using the "WHEN THE FILTER VALUE IS NOT IN THE URL" box in the Contextual Filter configuration. I had set the "Provide default value" setting to "Content ID from URL" based on a couple of references and trial and error and was wondering why it worked. I did not think about the fact that the block does not have an URL, so the filter needed to be pointed to the page URL. NODEONE videos helped with this and a couple of other points with Views.
I am also thinking that my only options for overriding the node template is to either (1) just give up and put modules and menu tabs into the existing node page or (2) use Page Manager to override the node template. If I can do this with just Views, please let me know how. I am not scared of Panels, but would like to keep the production site as lightweight as possible.
I still need some help understanding how the Views option of the Entity Reference field configuration works and needs to be configured to solve the problem statement. This configuration setting appears to have been implemented after NODEONE's video was published. If I figure more out through trial-and-error, I will post here.
A solution, but...
Okay, solution thus far...
I put an Entity Reference field into the Tasks Content Type using the Autocomplete Widget and configured in Simple mode under Entity Selection. Project is checked under Target bundles. I then created a View with a single page display. The basic Filter Criteria filters for Content Type = Tasks. Path is set to /node/%/parts and Menu is set to Tab: Parts. I have a single Contextual Filter that uses my Entity Reference field from the Tasks Content Type. I selected Show "Page not Found" from the options for Filter Value is Not in URL and left the rest stock. There is no Relationship created.
This works, but it seems quirky. If I set up a Relationship in the View, it breaks and renders a blank page, but I feel like I should be using a Relationship. I am still wondering what the Views mode in the Entity Reference field does, if I should use it, and how. I have not tackled the automation of prepopulating the Entity Reference field yet. I am thinking that is a Rules solution.
An aside - the first way I accomplished this was to use an integer field instead of the Entity Reference field. The View does not care what Content Type I am filtering so I just filter for the node ID from the project page URL in my integer field. I am wondering if this is a better solution for the instance where I don't want reference fields displayed for the user to monkey with. My end goal is for the user to look at a site page for the particular parent node, e.g. the project, and have a field available to enter new child node information, i.e. tasks. The site will, behind the scenes, associate the new task to the project being displayed; I think just a matter of entering the node ID from the project page URL into the reference field of the task node being created. My concern is that the autocomplete feature and translation of the Entity Reference field will eat up far more memory and performance, but looking for veteran opinion.
Performance impact of entity reference?
A half night's sleep and a cup of coffee and I am back at this.
Interim Conclusion 1: A field in the child content type that is used to identify the particular parent node that a child node is associated with is mandatory. (This may seem obvious, but I am trying to figure out exactly what the Views Relationship does in this context and wasn't sure how much magic power it has.) That field can be an Entity Reference field or something else, e.g. an integer field that contains the node ID of the parent node.
Interim Conclusion 2: The only time I need to create a relationship in Views is when I need to display unrelated content in the view display that is part of a node of another content type. So, if I wanted to display a list of the start dates of all of the projects that a particular task was part of, I would have to create a relationship (I think?). I am testing this theory now. But, I don't need a relationship to simply list all of the child nodes of a parent, i.e. child nodes that identify the parent in a field of the child node.
I am looking for validation of these conclusions, but Conclusion 1 begs the question: What are the differences between using an Entity Reference field and just an integer field with the parent node ID in it? If I choose 'Select List' as the widget type, does the Entity Reference field have the same functionality as it does using Autocomplete? And, is there any difference in site performance between using an Entity Reference field with 'Select List' as the widget type and using an integer field?
Ah ha, hidden field solved on add node solved... maybe.
I think I might have figured out another couple of pieces to the puzzle.
Interim Conclusion 3: While there may be many ways to override the default page setup for nodes, it appears that the Page Manager module offers the most flexibility and least custom coding and the most maturity. Until someone convinces me that it is too much of a performance hog, I am sticking with this.
Interim Conclusion 4: The Contextual Administration module appears to offer an out-of-the-box solution for hiding the Entity Reference field when a user is adding a new child node. So, I will try using this with Page Manager.