It would be nice to have one global token for whether the current global user is anonymous or authenticated.

You can kind of get this from the roles token, but then you get all other roles.

This is useful for google analytics custom variables which has token integration.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Dave Reid’s picture

How would you expect the token to work? Maybe seeing some sample output of the token would help.

thekk’s picture

FileSize
886 bytes

I have the same use case, but with Drupal 6.x. I've created the attached module to create a tokenvalue for ['user']['logged-in'].

Doing this in token_user.inc would require a 2 line patch.

greggles’s picture

Thanks for your comment and for helping make this a better module. Could you provide this as a patch?

thekk’s picture

Version: 7.x-1.x-dev » 6.x-1.x-dev
FileSize
1.26 KB

First time with tortoisegit, here's to hoping it works.

Again: I've done my work on the 6.x branch, I haven't looked into 7.x

greggles’s picture

Status: Active » Needs work

Looks like a good start. When you upload a patch be sure to set the status to "needs review" so others can find it.

I'm marking it "needs work" because it seems you used a tab for indentation rather than spaces.

I'm not sure whether the use of t() makes sense here. For my purposes it is to track users in google analytics so having different variable values for each user language wouldn't be desired. Perhaps we need two tokens, one that shows a text representation like you have and one that returns a 0 for anonymous and a 1 for authenticated. Thoughts?

thekk’s picture

Status: Needs work » Needs review
FileSize
1.25 KB

I agree that the use of t() doesn't really have purpose. I've scrapped it in the attached patch, as well as change the tabs to spaces.

I don't see much benefit (in google analytics), because most users would just have to think harder: does the '1' represent logged in or anonymous? Perhaps TRUE and FALSE? Do you have a usecase where you need the binary approach? But perhaps that's something for a different issue?

thekk’s picture

It would be appreciated if someone could take a look at this...

dbassendine’s picture

+1 - I've tested this patch and it works well. I'm using it for a Google Analytics custom variable.

Chris Charlton’s picture

Issue summary: View changes

+1 for this token. I know it's an oldie but it's a goodie.

greggles’s picture

Status: Needs review » Needs work

The patch in #6 looks close, but the spacing is still off.

@Chris Charlton - did you test out the patch? Does it meet your expectations from a functional perspective?