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.
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.
Comment | File | Size | Author |
---|---|---|---|
#6 | 1195324-auth-or-anon.patch | 1.25 KB | thekk |
#4 | 1195324-auth-or-anon.patch | 1.26 KB | thekk |
#2 | token_loggedin.zip | 886 bytes | thekk |
Comments
Comment #1
Dave ReidHow would you expect the token to work? Maybe seeing some sample output of the token would help.
Comment #2
thekk CreditAttribution: thekk commentedI 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.
Comment #3
gregglesThanks for your comment and for helping make this a better module. Could you provide this as a patch?
Comment #4
thekk CreditAttribution: thekk commentedFirst 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
Comment #5
gregglesLooks 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?
Comment #6
thekk CreditAttribution: thekk commentedI 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?
Comment #7
thekk CreditAttribution: thekk commentedIt would be appreciated if someone could take a look at this...
Comment #8
dbassendine CreditAttribution: dbassendine commented+1 - I've tested this patch and it works well. I'm using it for a Google Analytics custom variable.
Comment #9
Chris Charlton+1 for this token. I know it's an oldie but it's a goodie.
Comment #10
gregglesThe 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?