I'm embedding a viewfield on a content profile. I'm passing %author to the view, but the view doesn't validate it. I've tried most of the permutations of uid or user name to try to ascertain what %author was actually passing, but to no avail.

The fact that I am using a viewfield embedded in a Content Profile http://drupal.org/project/content_profile may have implications as to why this doesn't work.

cheers,
glass.dimly

CommentFileSizeAuthor
#11 viewfield-HEAD.arg-author.11.patch1003 bytessun

Comments

ericg’s picture

I'm having the same problem. After digging around a bit, I can say for sure that this is an issue for the Content Profile module and not viewfield.

repost this over there and I'll follow up as I work on a fix. For the short term, here's the workaround that I'd suggest (or at least this is what is working for me at the moment):

use %nid instead of %author in your viewfield
in your view, use an argument for User: Uid
in the argument settings section "Action to take if argument is not present: " click "Provide default argument"; in the section "Provide default argument options" click "PHP code" and in the field "PHP argument code:" put $userid = $node->uid;

ericg’s picture

actually, after a little more digging it does seem to be an issue for viewfield not content profile. I'll post a suggested patch in the next week or two

mherchel’s picture

@ericG - Did you ever finish creating the patch?

Thanks,

cregar’s picture

Is there a problem with %nid, too?
I have a view which definitely works with the right nid-argument. but when i edit the content profile the viewfield doesn't appear.

wonder95’s picture

I'm having this same problem, too. I'm using Viewfield on another node type where I'm passing %nid and it works fine, but when I use %author, it doesn't get passed at all. I've verified that my view works correctly when the uid is passed, so I know the problem isn't with the view.

wonder95’s picture

I haven't fixed this issue, but I thought I'd document my workaround, which was based on #1 above by @ericG.

However, there are a couple problems. The first is that he says to add %nid as an argument and then add PHP code under "Action to take if argument is not present: ". This code will not kick in if there is an argument, so you have to leave it blank in the viewfield settings.

The second problem is the code itself. The code has to return a value, so just putting

$userid = $node->uid

won't return a value. In addition, the $node object isn't available there, so you have to get it using menu_get_object(). This code

$node = menu_get_object();
return $node->uid;

works great.

It's still not a fix, but it will get around the problem.

Interesting note, though; it does appear that something is being passed to the view when %author is put in the viewfield config, because with the code above, I get no items displayed.

madt’s picture

I solved problem with %author as an argument by simply marking 'Enable token replacements.' checkbox. I tested this couple of times and it worked for me.

wonder95’s picture

That works for me, too, but it raises a couple questions/issues:

  1. If that checkbox is required, then why does %nid work fine? As I mentioned in my post, something was being passed when I used %author, since the default argument provided in the view itself wasn't being used.
  2. As noted in the help for that checkbox, "Token replacements will affect the site performance if using a Viewfield inside a View that has field row style." and I'm using a view with the fields style.
jonhattan’s picture

Component: Code » Documentation
Category: bug » task
Status: Active » Needs review

Same scenario here: using content profile + viewfield.

as far as I've tested:

1. %uid is not a valid replacement token (even not documented. How did you come to figure it out?).
2. %author is the node author uid. You can verify the view user:uid argument does not works with "Only allow string usernames". The other options accepting user uid are fine.
3. In point 1 I've put token in italics as the usual syntax for a token is [author], not %author. Anyway %author is considered a token in viewfield, and if you are using tokens you need to Enable token replacements.. If not... the argument to the view is "%author" (literal).

So I think this is not a bug report but a documentation issue. Suggestions:

* extend description on Arguments field to:

a) make explicit that %author will pass the author user uid to the view
b) make explicit that %something is a token and will not work as spected although you enable token replacements above.

sun’s picture

Component: Documentation » User interface
Status: Needs review » Active

There's no patch here?

sun’s picture

Version: 6.x-1.x-dev » 6.x-1.0
Component: User interface » Code
Category: task » bug
Status: Active » Fixed
StatusFileSize
new1003 bytes

Thanks for reporting, reviewing, and testing! Committed attached patch.

A new development snapshot will be available within the next 12 hours. This improvement will be available in the next official release.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

dadderley’s picture

I have pretty much the same scenario as the original poster.
I cannot get %author to pass to the view.
Does this work for anybody?

glass.dimly’s picture

workaround: set the default argument in the view.