1

I want to be able to add to my panel, described here, a view of an 'advocate' that 'endorses' an item.

Each item (unique by NID) has one Advocate (a user, unique by UID) and each User can have multiple endorsements (but still one per item).

In my view I have these settings:

http://i.stack.imgur.com/xwJVr.png
Click to view

I've annotated them to show how I think things link together

  • NID from the URL connects to the, 'Entity Reference: Endorsement'.
  • The Entity Reference: Endorsement connects to the '(Content entity referenced from field_tech_endorsement) Entity Reference: Endorser'.
  • The (Content entity referenced from field_tech_endorsement) Entity Reference: Endorser connects to the 'User: Name (Name) and User: Picture'

These settings all seem 'right' to me. but I'm getting no output on my panel.

I think the crux is in the Argument input, that it feeds from the NID selected on the panel (see link), and the UID of the associated (via the relationship Entity Reference: Advocate). But I don't know if I'm doing the 'feeding' right at all.

Nothing comes up on the preview, and nothing come up on the page.

This is what I'm hoping for:

Now with an endorsement

What am I doing wrong on this view? Is my set up right at all?

What I'm trying to do is reflect this set up:

Item->Endorsement->Advocate UML

Here is the SQL generated by the query.

<!-- lang-sql -->

SELECT      node.nid AS nid, #The node of the item that has this endorsement (?)
            users_field_data_field_endorser.name AS users_field_data_field_endorser_name, #The username of the advocate who has endorsed the item
            users_field_data_field_endorser.uid AS users_field_data_field_endorser_uid, #The UID of the advocate who has endorsed the item
            users_field_data_field_endorser.picture AS users_field_data_field_endorser_picture, #The picture of the advocate who has endorsed the item
            users_field_data_field_endorser.mail AS users_field_data_field_endorser_mail, #No idea why this is generated
            node.created AS node_created, #No idea why this is generated
            'node' AS field_data_body_node_entity_type #No idea what this is
FROM 
            {node} node #A Table of all nodes?
LEFT JOIN   {field_data_field_tech_endorsement} field_data_field_tech_endorsement ON 
                    node.nid = field_data_field_tech_endorsement.entity_id AND 
            (field_data_field_tech_endorsement.entity_type = 'node' AND 
            field_data_field_tech_endorsement.deleted = '0')
            #Left Join our endorsements, where they're not deleted, and they're NID matches their NID (well duh)
LEFT JOIN   {node} node_field_data_field_tech_endorsement ON 
                field_data_field_tech_endorsement.field_tech_endorsement_target_id = node_field_data_field_tech_endorsement.nid
             #Left join on Where the NID of the target matches the endorsement (????) That's not right
LEFT JOIN   {field_data_field_endorser} node_field_data_field_tech_endorsement__field_data_field_endorser ON 
                node_field_data_field_tech_endorsement.nid = node_field_data_field_tech_endorsement__field_data_field_endorser.entity_id AND 
                (node_field_data_field_tech_endorsement__field_data_field_endorser.entity_type = 'node' AND node_field_data_field_tech_endorsement__field_data_field_endorser.deleted = '0')
              #Left join on the endorser/advocate where the Endorsements NID is the same as the NID of the endorser/advocate's endorsement AND where the endorserment is endorsing the right kind of node, AND where the endorser is not deleted
LEFT JOIN   {users} users_field_data_field_endorser ON 
                node_field_data_field_tech_endorsement__field_data_field_endorser.field_endorser_target_id = users_field_data_field_endorser.uid
            #Left join on the user details that match the endorser
WHERE (( (node.nid = '13' ) )AND(( (node.status = '1') AND (node.type IN  ('endorsement')) )))
ORDER BY node_created DESC
LIMIT 1 OFFSET 0

I think my understanding of what it's doing it right, but it seems like what it's doing is wrong. What do I do to fix it?

  • 1
    Can you be more specific as to the relationships and their natures. And why the need for a User:UID contextual filter? – J. Reynolds Nov 25 '14 at 17:33
  • A useful way to debug if the problem is in the page of view configuration, is to create an empty text pane in the page, and input the tokens for your arguments passed into the page. That way you can get some insight into what exactly the page is doing and what is will pass on to Views. "Nothing comes up on the preview", which preview? If the page, then sadly I think that's expected. Page previews have been broken for a long time. If the View, then you know you've configured the View incorrectly. – Letharion Nov 25 '14 at 18:01
  • @Letharion how do I "create an empty text pane in the page, and input the tokens for your arguments passed into the page"? – Pureferret Nov 26 '14 at 9:24
  • @J.Reynolds It's so I can pass input to the view/panel. Thats what it's for...right? Also please see my edit with some hastily crafted UML. – Pureferret Nov 26 '14 at 9:24
  • 2
    @Pureferret Okay. so I don't think you need the UID contextual filter. You just need the nid as filter (which is already set up from the previous question). From the nid you filter the specific 'item'. from the 'item' you add a relationship to endorsement, and from the endorsement you add a relationship to the advocate. So your main work in views is in adding relationships correctly, and when you add fields to ensure they are set on the correct relationship. There are plenty of turotials based on that, ie this one – J. Reynolds Nov 26 '14 at 10:03
3

I've created these types:

  • Item (node) : has entity reference field to node of type endorsement.

  • Endorsement (node) : has entity reference field to user (which I guess has role advocate in your case)

The View: Base table of nodes, filtered by type 'Endorsement'

Two relationships:

  1. A bridge to the Content entity that is referencing Content via field_endorsement (as we have nodes of type endorsements in our base table, we need to link it to 'Item'. 'Item' has the entity reference field containing endorsement, hence we go in reverse: ie referencing)

  2. A bridge to the User entity that is referenced via field_advocate (as we have nodes of type endorsements in our base table we need to link it to User. Endorsements has an entity reference to user, hence it is a simple forward relationship, ie referenced)

Now add the Contextual filter of type nid. Set its relationship to 'Content referencing Content from field_endorsement', which was the first relationship added. The nid we are passing it is of type 'item', hence we must link it via the relationship to 'items'. Set 'hide view' 'when filter value is not available'.

enter image description here

For argument input: From panel argument, First argument.

Add your fields as you want. There is no need to add nid as a field unless you need to do so for a specific reason.

done with the view, back to the panel: add the view to the panel content for the page, and tick 'Send arguments'

|improve this answer|||||
  • This looks promising and I've made my set up as close to this as I can for now....but I can't be more thorough atm. Will go back over this later today/early tomorrow hopefully. – Pureferret Nov 26 '14 at 13:14
  • Perfect. No ideas what I was doing wrong but this works perfectly now. – Pureferret Nov 27 '14 at 10:14
  • J, my only issue is this one – Pureferret Nov 27 '14 at 12:22
  • This is great but I'm getting an anonymous user there instead of the endorser. I have a question, here – Pureferret Nov 27 '14 at 13:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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