1
votes

I'm using Drupal 7.12 and Views 3.3, and I want to create a Views block to put on a page, to show the current logged in user info they added to a set of custom profile fields. I have the fields created. Views is the problem.

I was able to create a Views block that shows the contents of the profile fields, but it makes a list of: 1 block of data for each user who has entered any data in these fields, and shows it to everyone. I only want it to show the current logged in user their own data.

I found a few mentions of adding a filter for "User: Current", but I don't have this option for this block. Then I found this item here:

Drupal 7 Views 3 user:current filter is missing?

Saying that I need to first add a relationship of "Content: Author", then I can add the "User: Current" filter. I wasn't able to do this either.

So, I decided to create a new Views block and see if I could figure out why these options aren't available to me. When creating a new Views block, one of the first things you do is select what to "Show", and there is a "Content" option, and there is a "Profile" option (and several others), but there is no way to select more than one option here. In the first Views block I created before I had selected "Profile" for content to show, and this removes all options in relation to content or anything else, this is why I can't make a relationship of "Content: Author". I'm not dealing with nodes of content. When I created my second Views block to test this, I selected "Show: Content", and I was able to create the "Content: Author" relationship, and then I was able to add the "User: Current" filter. But in this Views block I have no way to display profile field info.

Any help here will be very greatly appreciated!

5/2/12: Adding info on Filter and Relationship setting available to me on the "Profile" based Views block.

Filter options:

*Profile: Date changed - The date the profile was most recently updated.

*Profile: Date created - The date the profile was created.

*Profile: Label - The profile label.

*Profile: Location (field_location_us) - Appears in: profile2:main.

*Profile: Primary Issue (field_issue_area_primary) - Appears in: profile2:main.

*Profile: Profile ID - The unique ID of the profile.

*Profile: Total Operational Budget (field_total_op_budget) - Appears in: profile2:main.

*Profile: Total Org Staff (field_total_staff) - Appears in: profile2:main.

*Profile: Total Tech Staff (field_staff_tech) - Appears in: profile2:main.

*Profile: Total Technology/IT Budget: (field_budget_tech_total) - Appears in: profile2:main.

*Profile: Type - The profile type.

*Profile: User uid - The owner of the profile.

Add Relationships options:

*Profile: Type - The profile type.

*Profile: User uid - The owner of the profile.

That last item in both lists (Profile: User uid) seems like an obvious choice, but when I try it, from either list, my Views block shows no info at all, even though I do have information filled in. In fact every filter and/or relationship setting I've tried so far results in an empty Views block. I'm sure there's something I'm missing.

2

2 Answers

2
votes

I also posted this on the Drupal forum, as a support request for the Views module, and the info I got there led me to the right answer, and I want to share it here as well, in case it helps someone else. My post on the Drupal forum: https://drupal.org/node/1558544

Here is what I had to do (starting on the editing screen for my Views block):

1) Advanced (expand the section on the right) 2) Relationships [Add] 3) select "Profile: User uid" and apply 4) next screen is "Configure Relationship: Profile: User uid" - Identifier (admin label) box was pre-filled with "User" (no change made here) - Check the box for "Require this relationship" - Apply (save)

5) go to "Filter criteria", and click the "Add" button 6) check the box for "User: Current"*, and click the "Apply" button at the bottom 7) next screen is "Configure filter criterion: User: Current" - "Relationship" (drop-down box with one option): [User] - "Is the logged in user:" (yes/no buttons): select "Yes" - Apply (save)

8) On the main Views screen, be sure to save for this to be work live on the site.

9) It works. I now only see the info for the currently logged in user in this Views block!

  • Previously, I never got this configuration quite right, because I never saw the "User: Current" option.

Thank you very much for leading me to the answer!

~Christine

0
votes

What I understood from your problem is that you have set the fields, but the results are for all the users. So, most of the thing is already done, you just need to add the relationship of current user as mentioned in the link.

What it does is shows only the user's data who is logged in. Inside drupal, we get a global variable $user which will be added to the block view when you add the relationship.

You can find that thing on the right hand side of the view block settings inside the advanced tab. If using for the first time, it might be collapsed and you need to expand it.