Hi.
Resume : I want to create a view which display article content but with a filter using a user attribute.
I have added a 'city' attribute in user (field_city) and added a 'city' attribute in article based on taxonomy.
So when creating a node based on article, I set the city attribute to a term from a taxonomy vocabulary.
I want now to create a view which will display article from city = xxx where xxx is the value of the token [current-user:field_city]
I tried setting [current-user:field_city] in Filter criteria : not working
I tried using Contextual Filter : default value = [current-user:field_city] if value is not in url, but not working too.
Is someone managed to do the same thing I tried to do ? if so, how ?
Thanks.
Comments
I believe you want to add
I believe you want to add relationship on field_city between the content and user. Then you should be able to add a filter on current user.
relationship
thank for reply.
I tried to add a relationship from the view I created using "relationships" but I can't find my field in the list. Is there something to do to make my field appear ?
Ok, you need to relationships
Ok, you need to relationships.
The first one should be on the field with term reference (ex Field: color)
The second one will be on "Taxonomy Term: User using XXXX" where XXXX is the label of the term reference field in user.
Now you can add a filter on "User: Current" using the second relationship.
I found nothing
I added in my article content type :
label : Centre
System name : field_test
Type: Entity Reference
Entity type : taxonomy terme
Target bundles : my vocabulary (Centres)
In user configuration (/admin/config/people/accounts/fields), I added :
label : structure
System name : field_structure
Type : Text
I added a view "Articles Centre", for display block.
In relationShips, I just have the following choice, so I don't know which one to use :
For vocabularies I use a term
For vocabularies I use a term reference field (not entity reference). Not sure how it would work with an entity reference field.
Term reference
Thank, I changed entity reference to term reference in the content-type Article for the field_centre.
So I am able to create the two relationships :
the first one selecting "Content : Centre (field_centre)", so I understand that with this relationship, I am able retrieve the vocabulary term of the Article content.
the second one for "Taxonomy Term: Content using Centre". And it is where I am in trouble, because you tell me to add relationship on User using xxx and ont Content using xxx. There is no 'User using xxxx' in the list.
I added a third relationships to be able to have the current:user filter choice : a relationship on content:author
Then I don't kwown which "Filter Criteria" to use. I tried using User:structure (structure is the field of the user containing the vocabulary term associated with the Centre of the user).
I don't know if I have to use a token, or if I just need relationship.
You do not want the third
You do not want the third relationship since you want the user from step two and the the content author.
Starting point should be Field: yyy where yyy is the field name in the content. (not "Content: ...").
Then I added the second relationship and search for my field in user and found what I needed.
Solved
I finally managed to make the view I needed.
Using this post : http://drupal.stackexchange.com/questions/44327/filter-a-view-based-on-a... and https://www.drupal.org/node/1111722#comment-4315620
In fact, I needed to do a User view and not a Content view.
The view must retrieve the current user (it's must be a view on content = users and with using a contextual filters just get the current user), and with relationships get Article sharing the same field (for me = campus)
For information : no need to use token
Thanks for helping me.