Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I'm unable to filter nodes that have the same taxonomy terms as the user profile. I only want nodes to show that have at least one matching term.
Views settings below
Relationships
Node Revision: user
(user) User: Terms
Arguments
None
Filters
User: Active yes
(Terms for the user) User: Term - corresponding vocab selected
Thanks for the great module and for looking at my post.
Also, didn't know if this request was better suited for here or the forum, thought I'd try here first.
Comment | File | Size | Author |
---|---|---|---|
#20 | 721390_user_terms_default_arguments_3.patch | 8.95 KB | schultetwin |
#18 | user_terms_default_arguments_2.patch | 8.93 KB | schultetwin |
#17 | user_terms_argument_patch.patch | 7.4 KB | schultetwin |
#15 | user_terms_plugin_argument_default_taxonomy_tid.inc_.txt | 2.21 KB | schultetwin |
#15 | user_terms.patch | 4.13 KB | schultetwin |
Comments
Comment #1
joachim CreditAttribution: joachim commentedI don't understand what it is you're trying to do with that view.
- what type of view is it?
- which user profile? the current user doing the viewing? It looks from the setup you have that you are trying to say 'show me nodes where the node terms are the same as the terms of the node author'. I strongly doubt you will be able to get that out of Views.
Comment #2
jcolby1028 CreditAttribution: jcolby1028 commentedjoachim-
Thank you for your reply.
- what type of view is it? - Node View
- which user profile? - The current user
The project is a classifieds ad website similar to craigslist
I'm trying to have the user select his/her location and have it stored as a user term. When the user is looking at the Ads only the ones matching his/her location will show. This eliminates having to select a location every time the user visits the site.
If you tell me if there are any other means to achieve this I'd appreciate it greatly. I've tried many methods and with my limited coding ability I'm unable to customize modules, this module has been the closest to meeting my needs.
Thank you again,
Jesse
Comment #3
joachim CreditAttribution: joachim commentedOkay, so you don't want this AT ALL.
Anything you add to a view is to do with the items the view shows. So in this case, nodes. 'User terms' has no meaning for a list of nodes.
What you need is a term argument and some PHP argument handling code that supplies a default argument based on the current user's term. And I'm afraid to say you will need coding ability.
Comment #4
jcolby1028 CreditAttribution: jcolby1028 commentedBummer. Thanks for the information, you've saved me time and some frustration.
-Jesse
Comment #5
jcolby1028 CreditAttribution: jcolby1028 commentedComment #6
d0t101101 CreditAttribution: d0t101101 commentedI needed this functionality, and came up with this:
-Add Argument -> Taxonomy -> Taxonomy Term ID
-Provide default argument
-PHP Code
-PHP argument code:
-Check "Allow multiple terms per argument."
This allows me to create views showing only nodes that a user may like based on their user_terms selections. I hope to see this functionality built into the module, as its very useful for practically any site using user_terms!
Great module BTW,
.
Comment #7
d0t101101 CreditAttribution: d0t101101 commentedCorrection to the code above. This takes into account when a user hasn't setup their user_terms, and rather then displaying all, it returns none:
Comment #8
joachim CreditAttribution: joachim commentedLooks pretty good. You've got the main part of it there. If someone can wrap this up in a Views default argument plugin, I'll commit the patch.
A few minor points about the code:
- there's no need for either of those joins as the only thing you want back is the tid.
- use implode() instead of concatenation and trimming the last +
- you're using global $user which is all you can do in this code; however if this were a plugin I'd suggest trying to subclass the default user plugin so you can also get the terms from the user at a path like /user/UID/yourviewhere.
Comment #9
d0t101101 CreditAttribution: d0t101101 commentedWell I'd like to make REALLY good, so here you go :)
Regarding your last suggestion, would you kindly give me an example of how to "subclass the default user plugin"?
Thanks,
.
Comment #10
joachim CreditAttribution: joachim commentedLook in Views module at the existing plugins. Also, image module implements a default argument plugin -- see image_views_plugins().
Comment #11
jordojuice CreditAttribution: jordojuice commentedI know it's been a while since this post has been updated, but I have been looking for a way to do exactly this. I am using User Terms and need to be able to display a list of nodes with terms that match those on the user's profile. I made a Page and tried each of the samples above in a Node type Views argument but even with no filters all I got was a list of several duplicates of the current user instead of the nodes I was looking for. What could I have missed? I used all the same argument settings from #6 and other than that just a few fields and sorting criteria. Any help would be much appreciated.
Comment #12
joachim CreditAttribution: joachim commentedLike I said in #3, this requires custom code.
It could be added to this module if someone provides a patch. When I say 'someone', I mean one of the people commenting on this issue asking for the feature.
Comment #13
jordojuice CreditAttribution: jordojuice commentedI got it! I had separate vocabularies between the two, but when I switch to the same vocabulary it works great!
Comment #14
jordojuice CreditAttribution: jordojuice commentedGotcha. I think it's well worth it as many of us have spent hours getting nowhere on this. I see what I can do.
Comment #15
schultetwin CreditAttribution: schultetwin commentedAlright, so I was going to do this fairly extensively on my site, so I created this plugin. Please look at it and see what you think.
Patch file contains plugin file as well as additional code for user_terms.views.inc.
Comment #16
joachim CreditAttribution: joachim commentedThe patch looks pretty good.
Though it doesn't cover all the cases this issue is about: reading up I see we really have three different things being discussed here:
- get terms from the current user
- get terms from the author of the displayed node
- get terms from the displayed user profile
I'm not sure whether it's best to try to fold these all into one plugin or make separate ones :/
Comment #17
schultetwin CreditAttribution: schultetwin commentedOkay, I was able to get those as well. I totally changed the code, basing them off the to built in user arguments. I remade the patch. I've separated current user in one default argument, and displayed and user profile in the other (as is done in the user module).
Tell me what you think.
Comment #18
schultetwin CreditAttribution: schultetwin commentedSorry, I made a few more changes. The patch in #17 does not work.
Comment #19
joachim CreditAttribution: joachim commented> I totally changed the code, basing them off the to built in user arguments
Oh wow. That is really clever! :)
Just a few tweaks needed:
I'm not sure that we need this pattern. Why not just use the option name directly in the code? There's no reuse of things that need to refer to it that I can see.
Don't say $user when you don't mean the current user; it can lead to security holes if a 'global $user' is later added in the same scope. Use $account instead.
Comment #20
schultetwin CreditAttribution: schultetwin commentedI'm not sure why one would use the $option_name variable. I used it mostly because the plugins that comes with views use them. I don't see that it really matters either way, but if you'd like I can in and replace all instances.
Thank you for pointing out the $user variable thing, I forgot about that.
Comment #21
joachim CreditAttribution: joachim commentedYou've still got $option_name defined and then not used.
While you're rerolling, could you make sure:
- there's a newline at the end of each file
- roll from the base folder of the module rather than your base Drupal
A few tweaks for capitalization:
- 'title' => t('Taxonomy Term IDs from logged in user'),
- 'title' => t('Taxonomy Term ID from user URL'),
I've followed the pattern of existing Views plugins.
And while we're at it...
I much prefer a pattern where a variable is set and then returned, rather than returning an expression. It makes debugging much easier, as I just had to do to figure out why it wasn't working:
(BTW it didn't work because I am a numpty and added a user terms argument rather than node taxonomy...)
I'd quite like a one-line comment on each of the sections in get_argument, eg:
// Try to get a current node object and if there is one, its author.
Though if we have $user = menu_get_object('user', $i), why do we need if (arg(0) == 'user' && is_numeric(arg(1))) { ?
Also, can any of this be inherited from the parent class?
Comment #22
schultetwin CreditAttribution: schultetwin commentedSorry, haven't rerolled the patch yet. Probably won't happen until next week. This is the problem I'm running into. First, the reason to use $this->option_name is to allow other classes to extend you class. (So, effectively, there form options also app
The views_plugin_argument_default_user class defines it's form as:
$form[$option->name]
Which makes it hard to add additional form items to it. If I just chose not to use $option->name variable, then the fields that would appear for the default user argument only then appear for my argument. In short, I'm trying to find a way around that. I'm not sure the user classes are the best to use for this argument.
Mark
Comment #23
joachim CreditAttribution: joachim commentedOh right I get it.
The $option_name is actually some subform magic to make these element only appear when our radio button is selected.
And I see that you can't reuse anything much from the parent because of that. Hmm :/
Comment #24
schultetwin CreditAttribution: schultetwin commentedYeah. That's quite annoying. I could try posting a patch for views module, but I doubt that it will be used, as only bug fixes are going into views 2.x, and this won't be an issue for views 3.x.
I guess I could just build it for views 3, but I think it would be most helpful for most people, including myself for views 2.
Comment #25
rickh CreditAttribution: rickh commentedHey guys, is there any way to display the users who have the same user term. For example user being viewed has selected Apple as his favourite fruit. Other users who like apples.
Comment #26
rickh CreditAttribution: rickh commentedHey guys, implemented the patch and I get the following error in my view.
warning: array_filter() [function.array-filter]: The first argument should be an array in /home/woopycoz/public_html/sites/all/modules/user_terms/user_terms_plugin_argument_default_user_terms_current.inc on line 57.
Line 57 is included at options below