0

Background: This is not the first question asked around here. I thought I found a solution but nothing worked in the end.

I have 2 content type: Parent and Child

Child possess 2 Entity Reference(ER) fields, Section and Parent(ER)

Section is linked to a Parent node, Parent(ER) is linked to another Child node, allowing for 3 level of Hierarchy, level 1 being a Parent node, level 2 being a Child node with a Section, level 3 being a Child node with a Section and a Parent(ER). I have created a Child node name NONE and use it as default for Parent(ER) to easily distinguish between level 2 (with no Parent(ER)) and level 3 (with a Parent(ER)) nodes.

I'm currently trying to build the menu for Child pages using multiple views providing data. Currently, I have the Parent(ER) section of said menu down, as it's pretty easy to build. The problem comes when I try to create the Siblings. Here is the requirement for this view:

  • I need to list all level 2 Child nodes, so the ones with a Section but no Parent(ER) (already dealt with using a conditional filter on Parent(ER) and checking for all pages with the NONE nid.)

  • I need to remove the currently displayed Child node as it's already present elsewhere

  • I need to print ONLY Child with the same Section as the current node

I can't find the contextual filter/relationship combination to achieve my goal.

How can I achieve this?

1
  • 1
    Your explanation about what is related to what isn't clear. Can you please rewrite your Question to clarify that. Does Section have an ER towards Parent? Then Section can be viewed as Sibling to Child. What do you mean by level 2 and level 3?
    – prkos
    Commented Aug 16, 2018 at 17:29

1 Answer 1

1

Your levels are a bit confusing, I'm guessing it's to do with your project structure and doesn't provide relevant information about the reference hierarchy, so I'll just rely on the information you provided about which entity references which.

list all Child nodes with a ref to Section but no Parent(ER)

Even though you already solved this the solution that first comes to my mind is to list all Child pages where the ER field to Section isn't empty, and the ER field towards Parent(ER) is empty. No need for special NONE nodes.

You can do this by adding a Filter for each of those ER Fields and setting the Operator to Is empty (NULL) and Is not empty (NOT NULL) respectively.

Remove the current node from the list

Add a Contextual filter ID from the Content Category and configure it with these options:
When the filter value is NOT available
Provide default value
Content ID from URL
More
Exlude

List siblings relating to same node through ER

To list siblings you first need one Relationship to get to the parent of the ER relationship (in your case Section), then another Relationship in reverse direction that is using the first one to find all other children of the parent. Then configure a Contextual filter to use the second Relationship, that is the one that is identifying siblings.

  1. Add a Relationship Content referenced from field_section (or however it's called in your particular case), you can require it, this introduces the Section into the Views.
  2. Add another Relationship Content using field_section, set it to use the Relationship from the previous step, you can require it. This is the reverse direction, pointing to all children that are pointing to this parent (Section).
  3. Add a Contextual Filter ID from Content Category and set it to use the second relationship (field_section) and configure:
    When the filter value is NOT available
    Provide default value
    Content ID from URL
    When the filter value IS available or a default is provided
    Specify validation criteria
    Child
  4. If this is a Block Display place it on Child nodes and it will show other children that relate to the same Section.

To check the Contextual filter with Views Preview, enter the NID of the Child node you want to simulate, and enter it for each Contextual filter.

If you have both the contextual filter that identifies siblings and the one that excludes the current node from the list (and the Child NID is 24) enter 24/24.

If you want to see all the results, unaffected by Contextual filters enter all/all.

Your Answer

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

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