For this Views preview we use the nid of C 4, and get the following output of node titles: To get all C nodes it’s done the same way.įinally, to output the titles of all those C nodes, we use the correct relationship for that field. Again, include the previous relationship. So, we use A bridge to the Content entity that is referenced via field_b. So, now we’ve got content that is referenced. Now we want to go back down the chain and get all B nodes. And we’re connecting it to the previous relationship. Again, the content this relationship gives you is doing the referencing. A bridge to the Content entity that is referencing Content via field_b. To get the A node we need another relationship for the entity reference field in A nodes I’ve named field_b. To make things easier to read we’re setting the Identifier and the Administrative title. Thus we’re using an entity reference relationship called A bridge to the Content entity that is referencing Content via field_c.Įach B node has an entity reference field to its C nodes. Next we setup the layers of relationships. To do this with Views, we start with a contextual filter of the current node. Finally, all C nodes referenced by the B nodes. Next all the B nodes referenced by the A node. To do that, you need the B node referencing your C node. Let’s say we’re on the page for node 4, of Content Type C, and on this page we want to list all the related nodes that are of Content Type C. This will become more clear as we go through our example. A bridge to the Content entity that is referencing Content via field_other_content means your entity has the reference field. Or is it A bridge to the Content entity that is referenced via field_content?Ī bridge to the Content entity that is referenced via field_content means your entity is referenced by another via an entity reference field. Is it A bridge to the Content entity that is referencing Content via field_other_content When trying to set this up in views, relationship descriptions for entity reference fields don’t help. Content Type B has an entity reference field to Content Type C: Rather than go through the specific case with our client, I’ve setup a very general one.Ĭontent Type A has an entity reference field to Content Type B. Trying to debug the query built by Views looks even scarier.Ĭlayton Dewey was able to assist me, and we got relationships working even when needing to chain five different nodes together through their reference fields. And, I create and/or modify Views with complicated relationships so infrequently that I never remember how to do it. When you try to relate content to content to content, the permutations of configuration options in Views gets a little unwieldy. When it comes to relationships in Views, creating a relationship from one content type to another, the number of permutations is usually small enough that it only takes a few minutes to try all of them until you get the desired output. With Views, all of that can be easily cached. I also considered doing all of this in code but that could mean running a number of extra database queries on every page load. This wasn’t really possible as a menu block because the links needed to contain some of the actual content. The project included a sidebar of links to all the related content that spanned three content types. We recently added new functionality to a client’s site that involved Entity References to group content and display it dynamically. The results can be great, but setting up Entity References across content types with Views can be. Views relationships using Entity References across more than one content type can be used to establish multi-tiered content relationships. If you're not already familiar with the subject, check out Joel Steidl's intro to Entity References.ĭrupal has some powerful tools for creating and managing complex content relationships.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |