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

nevets’s picture

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.

blink38’s picture

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 ?

nevets’s picture

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.

blink38’s picture

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 :

Commentaire: Comments of the node
Relate all comments on the node. This will create 1 duplicate record for every comment. Usually if you need this it is better to create a comment view.

Commentaire: Last Comment
The last comment of a node.

Content revision: Contenu
The revision NID of the content revision.

Content revision: Contenu
The revision ID of the content revision.

Content revision: Utilisateur
Relate a content revision to the user who created the revision.

Contenu: Auteur
Relate content to the user who created it.

Contenu: Image (field_image:fid)
Appears in: node:article.

Contenu: Last comment author
The User ID of the author of the last comment of a node.

Contenu: Tags (field_tags)
Appears in: node:article.

Contenu: Taxonomy terms on node
Relate nodes to taxonomy terms, specifiying which vocabulary or vocabularies to use. This relationship will cause duplicated records if there are multiple terms.

Contenu: Webform submission
Webform submissions of the given Webform node.

Entity Reference: Referenced Entity
A bridge to the Terme de taxonomie entity that is referenced via field_test

Feeds item: Owner feed
Relate a feed item to its owner feed node if available.

Feeds log: Feed node
Relate a log entry to its feed node if available.

Feeds log: Importer
Relate a log entry to its importer if available.

File Usage: Fichier
A file that is associated with this node, usually because it is in a field on the node.

Webform: Nœud
The node this webform is part of.
nevets’s picture

For vocabularies I use a term reference field (not entity reference). Not sure how it would work with an entity reference field.

blink38’s picture

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.

nevets’s picture

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.

blink38’s picture

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.