Download & Extend

Global token for whether user is anonymous or authenticated

Project:Token
Version:6.x-1.x-dev
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:needs review

Issue Summary

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.

Comments

#1

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

#2

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.

AttachmentSizeStatusTest resultOperations
token_loggedin.zip886 bytesIgnoredNoneNone

#3

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

#4

Version:7.x-1.x-dev» 6.x-1.x-dev

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

AttachmentSizeStatusTest resultOperations
1195324-auth-or-anon.patch1.26 KBIdleFAILED: [[SimpleTest]]: [MySQL] 28 pass(es), 15 fail(s), and 5 exception(es).View details | Re-test

#5

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?

#6

Status:needs work» needs review

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?

AttachmentSizeStatusTest resultOperations
1195324-auth-or-anon.patch1.25 KBIdlePASSED: [[SimpleTest]]: [MySQL] 175 pass(es).View details | Re-test

#7

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

nobody click here