Hi,

I'm creating a site that is used as my company's internal website. I've created a content type that can be used to provide feedback to users of the site (as a performance management tool).

I have set the Management role with permission to be able to create the content type "Employee Feedback".

In the Content Type I have added the Entity Reference field so that the Managers can select a user from the list of users, as well as a Long Text area to write the comments/feedback.

My issue is that I would like to create a View for users to be able to see the Feedback that has been left for them (and them alone). How do I create a view and filter it based on the User that is selected in the Content Type? Users should only be able to view feedback that has been left for them (their username was what was selected in the "Employee Feedback" content type).

Thank you for any help and suggestions you may have.

Comments

VM’s picture

you''ll need to investigate how to work with contextual filters & relationships in the view. I suggest reviewing the nodeone taming the beast videos for the aforementioned topics.

kyleheney’s picture

Thank you for the guidance. NodeOne seems like a really good resource. Much appreciated.

kyleheney’s picture

Struggling...

I have added a "User Reference" field to my content type. The manager can select a user and provide feedback.

My issue is around creating a View that can be accessed by users that allows them to see feedback that has been left for them (and only them). I have tried adding the Relationship to the User Reference field, but this doesn't seem like enough.

All I want is for the view to be viewable to the user that is selected in the User Reference field.

I just can't figure it out!

VM’s picture

Did you set a contextual filter? if yes, what did you set it at?

kyleheney’s picture

Wow thanks for the nudge in the right direction... I had been using a Contextual filter, but I needed to set it to "Provide Default Value"; Type: User ID from logged in user.

This is great. I'm going to do a bit more testing to make sure, but I think I got it. Thanks a lot and thanks again for the link to Nodeone! It seems like a great resource.

kyleheney’s picture

Related question...

I've figured out how to make the Contextual Filter work so that it filters the submissions based on the User Reference.

My issue now is that I don't know how to prevent access to other users' feedback (by simply altering the URL to another user's UID).

The path I am using for this view is "user/*/my-feedback". I have also set it up as a tab in the My Account section. The problem is that I can't seem to figure out how to deny access to other user's "My Feedback" tab in My Account. Ideally, a user should only be able to see their own Feedback.

VM’s picture

kyleheney’s picture

Your comment is coming up as blank...?

VM’s picture

I started to comment on something which upon review was determined insufficient direction. As such I withdrew the comment.

you have access control within the view which can you investigate. You may also have to dig a but more in the contextual filter setting. There is a way to do what you are asking for. I'm just not in the position of being able to dig at moment. I'd venture the question has been asked before. As such a google search of drupal.org may be of benefit. May also be worth hopping in IRC.

kyleheney’s picture

I've definitely been googling for a few hours and I think I finally found what I needed.

I accomplished this by using the Views PHP module and inserting this code in the Access settings of the view:

global $user;
return $user->uid == arg(1);

The Views PHP module page makes it seem like it might not be the best module to use due to performance issues, but I am finding it works perfectly for this function. I believe I have finally solved this one and I hope this can be of help to anyone else in the future.

1) Create View for whatever Content Type/Entity you want to display (I used EntityForm Submission because I have a "User Reference" field on my EntityForm to reference a particular user)
2) Add the necessary Fields to your view
3) Change the path to "user/*/menutabheading" (this will make a tab in the My Account section)
4) Create Menu tab; using User Menu as menu
5) Use the Access setting/code above to restrict access so that the logged in user can only content that they were "mentioned" in (only view content where they were selected in the User Reference field)
6) Contextual Filter: "Provide Default Value: User ID from logged in user"

Really hope this helps someone else as it took a while to figure out!

Thanks for your help @VM