0

[![enter image description here][1]][1]I have a content type of "School." I have a content type of "Event" that contains an entity reference to "School" so that events can be linked to schools. I can create a view block that filters by the school, when the block is placed on the node of the school, using contextual filters.

The problem: Starting with the built-in "Basic Page," I added an entity reference to "School" so that "Basic Pages" can be linked to a "School," and be subpages of the "School." How do I filter a view of "Events" that when placed on a "Basic Page" the "Events" block view will filter based on the entity reference, "Schools," that is shared between the "Event" and "Basic Page?" I am looking to have an "Events" subpage that lists all the events of that individual school. I am trying to avoid having to create separate block views that use filter criteria of each individual school. I was hoping to use contextual filters.

Thank you

1 Answer 1

0

You can, at least in D8 use "reverse entity references" in contextual filters and relationships, so what you propose should work.

Have a contextual reference grabbing the node id of the Basic page from the URL. A relationship from the page to the school comes next, then a reverse relationship looking for items that have a relationship to the School. You'll also add a filter on that second relationship, limiting it to Events.

8
  • a little more help please. My entity reference on both "Events" and "Page" is LINK TO SCHOOL. First Relationship - field_link_to_school:Content (Appears in: article, page, event) Second Relationship - field_link_to_school (Relate each Content with a field_link_to_school set to content item.) AND this has a relationship back to the first relationship. Everything seems good to start when I filter to "Event." Events that are related to any school displays. But when I add a contextual filter to node id nothing will display on the page. Imgur
    – x00cooper1
    Feb 18, 2020 at 17:23
  • In the contextual filter you need to set "when the filter value is not available" to provide a default as the content ID from the URL. You can test by putting in an appropriate id in the preview box.
    – beltouche
    Feb 18, 2020 at 17:49
  • I did that but now realized that for the contextual filter, I needed to use the reference. Thank you @beltouche
    – x00cooper1
    Feb 18, 2020 at 18:53
  • Sorry, just tested and it does not completely filter out by School, just by content type of Event. Events with a LINK TO SCHOOL is another school still show.
    – x00cooper1
    Feb 18, 2020 at 18:59
  • As I noted in main response, you'll need to add filters on the related entities. Can you post another image of the settings you have so far? Especially the contextual filters and relationships.
    – beltouche
    Feb 18, 2020 at 19:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.