I'm trying to create a view that displays a teaser list of some user's created content on a website, so I created a node type view using the Node row style using a Page display with this path: 'expert/%'
To filter results I tried using the 'User: Name' argument to get, for example, something like '/expert/jane-marsh' on the URL alias, displaying all content authored by 'Jane Marsh'. When I try this, I always get an empty result.
The odd thing I noticed is that the module transforms the user name I pass as an argument into that user's UID, but tries to put this number into the user.name field in the WHERE clause of the resulting query, giving an empty result, as I have no user registered by the name '3' (Jane Marsh's UID).
For example:
SELECT node.nid AS nid
FROM node node
INNER JOIN users users ON node.uid = users.uid
WHERE (node.status <> 0) AND (node.type in ('article', 'video')) AND (users.name = '3')
when the WHERE clause should really be:
WHERE (node.status <> 0) AND (node.type in ('article', 'video')) AND (users.name = 'Jane Marsh')
I use the User validator, set to only allow string usernames, and I put the Lowercase in path transform setting, with spaces turned into dashes. (This transformation never works, by the way, I always get 'expert/Jane Marsh' on my URL).
Is this a bug? or am I using this argument incorrectly?
Comment | File | Size | Author |
---|---|---|---|
#5 | user-argument-validator-406666.patch | 2.12 KB | stormsweeper |
Comments
Comment #1
merlinofchaos CreditAttribution: merlinofchaos commentedCan you please paste an export of your view?
I suspect you've got the user name argument validator set to transform the name into a number. Either that or you've got aliasing set up which is causing the transformation to happen before Views ever gets to it.
Comment #2
rafaelcr CreditAttribution: rafaelcr commentedThanks for your reply, here's my exported view:
I noticed the problem arises if I set the Validator to 'User' in the Validator options of the argument. I don't know if there's an option to transform the username into a number for building the query, at least one that I'm aware of!
If I set it to 'Basic Validation', the view works just fine, the query is built with the user name instead of the UID and I get the expected results.
Comment #3
stormsweeper CreditAttribution: stormsweeper commentedI have the same issue. SQL query as shown in preview and export:
Comment #4
stormsweeper CreditAttribution: stormsweeper commentedLooking into this more, the User argument validator always makes the argument value the uid, so you can get more or less the right results using the "User: Uid" argument instead, although the argument in the URL must still match the username exactly.
Comment #5
stormsweeper CreditAttribution: stormsweeper commentedAttached is a patch for the user argument validator that allows you to specify whether it should return the UID or username as the value (defaults to UID and should not break existing UID validation). The other user argument options mentioned in the initial issue are unaffected by this patch.
Comment #6
merlinofchaos CreditAttribution: merlinofchaos commentedThis seems silly. If you've loaded the user and have an ID, you should absolutely use the ID, as looking up by UID is more performant than looking up by NAME. I don't think this is a good idea.
Comment #7
stormsweeper CreditAttribution: stormsweeper commentedAgreed, just going for flexibility.
Honestly, the issue the OP is having canb't really be resolved, since there's no reliable way to go from url-munged value to text value in all cases (namely "User Name" and "User-Name" are both valid usernames). Pathauto does it by just storing all the aliases it makes. I had a similar need and ended up going with duplicating displays since I had only 4 users to worry about.
Comment #8
mrtoner CreditAttribution: mrtoner commentedProblem still exists in 6.x-2.8. I'm going to mark this as a duplicate of a more recent issue, #744468: Argument User:Name looks for User:Uid; I know, it's usually the other way around, but this issue seems to have gotten lost in the cracks -- perhaps the newer issue will get more attention.
In my issue I noted that I was able to work around the problem. Based on stormsweeper's line of thought I changed my validator and User:Name now validates.